2017/12/24

tmux

Common Shortcuts

test

# start new session
$ tmux new -s myname

# list sessions
$ tmux ls

# attach to session
$ tmux a -t 0

# rename session
$ tmux rename-session -t 0 NEW_NAME

# kill session
$ tmux kill-session -t 0

Windows Control

  • <prefix> c create window
  • <prefix> w list windows
  • <prefix> n next window
  • <prefix> p previous window
  • <prefix> f find window
  • <prefix> , name window
  • <prefix> & kill window
  • <prefix> [ check history

Pane Control

  • <prefix> % vertical split
  • <prefix> " horizontal split
  • <prefix> o swap panes
  • <prefix> q show pane numbers
  • <prefix> x kill pane
  • <prefix> q (Show pane numbers, when the numbers show up type the key to goto that pane)
  • <prefix> { (Move the current pane left)
  • <prefix> } (Move the current pane right)
  • <prefix> z toggle pane zoom

Resize Pane

  • <prefix> : resize-pane -D (Resizes the current pane down)
  • <prefix> : resize-pane -U (Resizes the current pane upward)
  • <prefix> : resize-pane -L (Resizes the current pane left)
  • <prefix> : resize-pane -R (Resizes the current pane right)
  • <prefix> : resize-pane -D 20 (Resizes the current pane down by 20 cells)
  • <prefix> : resize-pane -U 20 (Resizes the current pane upward by 20 cells)
  • <prefix> : resize-pane -L 20 (Resizes the current pane left by 20 cells)
  • <prefix> : resize-pane -R 20 (Resizes the current pane right by 20 cells)
  • <prefix> : resize-pane -t 2 20 (Resizes the pane with the id of 2 down by 20 cells)
  • <prefix> : resize-pane -t -L 20 (Resizes the pane with the id of 2 left by 20 cells)

Start With Configuration

#!/bin/bash
tmux -2 new-session \; \
send-keys 'cd /var/www/test; vim' C-m \; \
split-window -h \; \
send-keys 'top' C-m \; \
resize-pane -R 30 \; \
split-window -v \; \
send-keys 'while true; do date; sleep 1; done' C-m \; \

My Config

# ~/.tmux.conf
set -g default-terminal "xterm"
setw -g mode-keys vi

# ~/.bashrc
alias tmux='tmux -2'

Auto Start Config

#!/bin/sh

SERVICE=apache_watcher

tmux has-session -t $SERVICE

if [[ $? != 0 ]]; then
	tmux new -s $SERVICE -d

	tmux split-window -h
	tmux split-window -v -t $SERVICE:0.1
	tmux split-window -v -t $SERVICE:0.0

	tmux send-keys -t $SERVICE:0.0 'htop'  C-m
	tmux send-keys -t $SERVICE:0.2 'nload' C-m
	tmux send-keys -t $SERVICE:0.3 'sudo apachetop' C-m

	tmux clock-mode -t $SERVICE:0.1
	tmux resize-pane -R 30
fi

tmux a -t $SERVICE

Reference Site

https://gist.github.com/MohamedAlaa/2961058
https://blog.htbaa.com/news/tmux-scripting

沒有留言:

張貼留言