Ch6
Chapter 6 : Workflowsπ
Working Effectively with Panes and Windowsπ
Turning a Pane into a Windowπ
- For popping a pane into a window :
PREFIX !
Turning a Window into a Paneπ
- We can use
PREFIX :join-pane -s panes:1
to join first window in a session named panes to current window.
Maximizing and Restoring Panesπ
- We can temporarily make a pane go full screen :
PREFIX z
. It works kinda like toggle switch
Launching Commands in Panesπ
- To access two server in one window with two panes use this script.
tmux new-session -s servers -d "ssh deploy@burns"
tmux split-window -v "ssh dba@smithers"
tmux atttach -t servers
Note there is a handy side that when pipe breaks and server disconnects, panes will autoclose.
Opening a Pane in Current Directoryπ
We can use #{pane_current_path}
provided by tmux for this use.
# split pane and retain the current directory of existing pane
bind _ split-window -v -c "#{pane_current_path}"
bind \ split-window -h -c "#{pane_current_path}"
Issuing Commands in Many Panes Simultaneouslyπ
Using the command set-window-option synchronize-panes on
, anything you type in one pane will be immediately broadcast to the other panes in the current session.
Then we will need to disabled the broadcast. set-window-option synchronize-panes off
Rather than that we can make a toggle binding : PREFIX CTRL-s
Managing Sessionsπ
Moving Between Sessionsπ
Start two session as
Then connect to editor session : tmux a -t editor
To switch session use : PREFIX (
and PREFIX )
To see list of active sessions : PREFIX s
Moving Windows Between Sessionsπ
- You can use
PREFIX :move-window
orPREFIX .
, so you can bring up window you want to move, press the key combination and write the name of target session.
Creating or Attaching to Existing Sessionπ
if ! tmux has-session -t development; then
exec tmux new-session -s development -d
# other setup commands before attaching...
fi
exec tmux attach -t development
Tmux and Your OSπ
Using a Different Shellπ
Launching tmux by Defaultπ
Add following script block to load tmux by default
Keeping Specific Configuration Separateπ
Move your OS-specific configuration into a separate file and tell tmux to load it up using tmuxβs if-shell
commands and the source
command.
Add your mac specific stuff in the file above then in main .tmux.conf
write
Similarly for loading your secret tmux sauce :)
Recording Program Output to a Logπ
With pipe-pane, you can toggle it on and off at will and you can start it after a program is already running.
To activate this : PREFIX :pipe-pane -o "cat >>mylog.txt"
fix the tmux conf
# log output to a text file on demand
bind P pipe-pane -o "cat >> ~/#W.log" \; display "Toggled logging to ~/#w.log"
Now you can use PREFIX P
to toggle logging in file.
Adding Battery Life to Status Lineπ
wget --no-check-certificate https://raw.github.com/richo/battery/bin/battery
chmod +x ~/batter
# check if its working
~/batter Discharging
Adding it to tmux config
# Status line right side - 50% | 31 Oct 13:37
set -g status-right "#(~/battery Discharging) | #[fg=cyan]%d %b %R"
Integrating Seamlessly with Vimπ
Install vim-tmux-navigator
plugin in vim using Plug or Vundle.
Then to easily navigate add this config to your .tmux.conf
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
Β | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind-key -n C-h if-shell "$is_vim" "send-keys C-h" "select-pane -L"
bind-key -n C-j if-shell "$is_vim" "send-keys C-j" "select-pane -D"
bind-key -n C-k if-shell "$is_vim" "send-keys C-k" "select-pane -U"
bind-key -n C-l if-shell "$is_vim" "send-keys C-l" "select-pane -R"
bind-key -n C-\ if-shell "$is_vim" "send-keys C-\\" "select-pane -l"
# Clears screen
bind C-l send-keys 'C-l'
Extending tmux with Pluginsπ
Bruno Sutic developed a solution TPM (tmux plugin manager to deal with the config file problems).
Letβs install tmux-resurrect
to restore tmux session even after a reboot!!!
Add following Lines to .tmux.conf
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-resurrect'
run '~/.tmux/plugins/tpm/tpm'
To install plugin PREFIX I
To save current tmux window/pane state : PREFIX CTRL-s
To restore last state : PREFIX CTRL-r