helpful links

Starting session

  • tmux attach -t TMUX: attach existing session with name “TMUX”
  • tmux new -s TMUX: create new session with name “TMUX”

.zshrc

Update 2024-11-26:

  • I’ve commented this out and opt to start tmux manually. I also commented out the MOTD / user information.
# ~/.config/zsh/zshrc
 
# attach tmux session automatically or start new tmux session
if [ -z "$TMUX" ]
then
    tmux attach -t TMUX || tmux new -s TMUX
fi
 
# print ssh motd and last login (as starting tmux overwrites this on ssh login)
# removed this as of Oct 2024
if [ -n "$TMUX" ]; then
 
  # message of the day
  if [ -f /etc/ssh/mybanner ]; then
    cat /etc/ssh/mybanner
  fi
 
  # last login
  last $USER |awk 'NR==2 {
    if (NF==10) { i=1; if ($3!~/^:/) from = " from " $3 }
    printf("Last login: %s %s %s %s%s on %s\n",
      $(3+i), $(4+i), $(5+i), $(6+i), from, $2);
    exit
  }'
fi

Configuration file

Updated 2024-11-26:

  • Configure keybinds for switching windows more prominently (as opposed to panes)
  • Bind F12 to disable/enable keys (for nested sessions) - thanks to this configuration
# Reference:
# M-x = Alt + x
# M-X = Alt + Shift + x
# C-x = Ctrl + x
 
# bind leader key to Ctrl + a - use Ctrl + s for nested tmux sessions on remote server
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
 
# list keybinds with Alt + ?
bind -n M-? list-keys
 
# rebind split windows to easy-to-remember keys
unbind % # default horizontal split
unbind '"' # default vertical split
bind -n M-\\ split-window -h
bind -n M-- split-window -v
 
# rebind pane switching to Alt + vimkeys
bind -n M-\: last-pane
bind -n M-H select-pane -L
bind -n M-J select-pane -D
bind -n M-K select-pane -U
bind -n M-L select-pane -R
bind -n M-< swap-pane -D
bind -n M-> swap-pane -U
 
# rebind window switching to Alt + Shift + vimkeys
unbind c # default new window
unbind n # default next window
unbind p # default previous window
unbind \; # default last pane
bind -n M-e new-window
bind -n M-k next-window
bind -n M-j previous-window
bind -n M-\; last-window
 
# add additional independent Alt + # keybindings to switch windows
# leave existing keybinds
bind -n M-1 select-window -t :=1
bind -n M-2 select-window -t :=2
bind -n M-3 select-window -t :=3
bind -n M-4 select-window -t :=4
bind -n M-5 select-window -t :=5
bind -n M-6 select-window -t :=6
bind -n M-7 select-window -t :=7
bind -n M-8 select-window -t :=8
bind -n M-9 select-window -t :=9
 
unbind x # default kill pane
bind -n M-x confirm-before -p "kill-pane #P? (y/n)" kill-pane
unbind d # default detach
bind -n M-q detach-client
unbind & # default kill window
bind -n M-Q confirm-before -p "kill-window #W? (y/n)" kill-window
 
# set clickable windows
set -g mouse on
 
# reload config file (change file location to your the tmux.conf you want to use)
bind r source-file ~/.config/tmux/tmux.conf
 
# fix escape delay in terminal vi mode
set -sg escape-time 0
 
# start window index at 1 instead of 0
set -g base-index 1
set-window-option -g pane-base-index 1
 
# toggle keybinds (for when in nested sessions)
 
bind -T root F12  \
  set prefix None \;\
  set key-table off \;\
  if -F '#{pane_in_mode}' 'send-keys -X cancel' \;\
  set window-status-current-format "#I:#W"
  refresh-client -S \;\
  # set status-style "fg=$color_status_text,bg=$color_window_off_status_bg" \;\
  # set window-status-current-format "#[fg=$color_window_off_status_bg,bg=$color_window_off_status_current_bg]$separator_powerline_right#[default] #I:#W# #[fg=$color_window_off_status_curr
ent_bg,bg=$color_window_off_status_bg]$separator_powerline_right#[default]" \;\
  # set window-status-current-style "fg=$color_dark,bold,bg=$color_window_off_status_current_bg" \;\
 
bind -T off F12 \
  set -u prefix \;\
  set -u key-table \;\
  set -u status-style \;\
  set -u window-status-current-format \;\
  refresh-client -S
  # set -u window-status-current-style \;\
  # set -u window-status-current-format \;\
 
wg_is_keys_off="#[fg=$color_light,bg=$color_window_off_indicator]#([ $(tmux show-option -qv key-table) = 'off' ] && echo 'OFF')#[default]"
 
set -g status-right "$wg_is_keys_off"

WSL Windows Terminal specific reference

  • Line selection: hold Shift (does not work nicely with multiple windows)
  • Rectangle selection: hold Alt+Shift
  • Deselect: Esc

EOF