How I use tmux
The primary reason I use tmux
(and originally screen
) was so I don’t lose my current working directories when I accidentally close my terminal window(s). tmux attach
and you are back where you fat fingered a cmd+w
or cmd+q
.
The second reason is because I have a number of projects (and their directories) I work on, so I have a little tmux configuration file called .tmuxdev
that I run every time I reboot and start tmux by doing this:
tmux #start tmux
ctrl-w-: source ~/.tmuxdev #source the script
.tmuxdev
looks like this:
neww
send-keys 'cd ~/path-to-project1' Enter
renamew 'project1'
killw -t 0
neww
send-keys 'cd ~/path-to-project2' Enter
renamew 'project2'
neww
send-keys 'cd ~/path-to-project3' Enter
renamew 'project3'
#2 panes
neww
send-keys 'cd ~/path-to-project4/frontend' Enter
renamew 'project4'
spl
send-keys 'cd ~/path-to-project4/backend' Enter
#And so on
Then in tmux, I can do ctrl-w
and f
to find a window by their names like project1
.
I also have a few more personalized keybindings that is more consistent with my workflow with vi:
set -g prefix C-w #consistent with my vi bindings
bind j select-pane -D
bind k select-pane -U
bind h select-pane -L
bind l select-pane -R
bind 9 select-pane -l
bind 9 run-shell "tmux select-window -t $(tmux list-windows | awk 'END{print NR-1}')" #last window
#Overrides default binding which does find-window too, but now case insensitive
bind f command-prompt "find-window -i '%%'"
bind -n C-h previous-window
bind -n C-l next-window
bind -n C-o last-window