tmux
Table of Contents
1. Launcher
The idea is to need a single key binding, in this case M-t (alt+t), in order to run any tmux commands or shell scripts
# ~/.config/tmux/tmux.conf # Launcher bind-key -n M-t display-popup -E -T " #{host} " -h 60% -w 80% "$HOME/.config/tmux/launcher"
The key binding will run this launcher shell script inside a tmux popup and it will look for a specific line in every scripts under ~/.config/tmux/scripts, the result is a list of scripts to choose from
Inspired by gotbletu tmux setup explained in this YouTube video
2. Copy text with copy-mode
Using custom bindings with C-t as prefix
# ~/.config/tmux/tmux.conf set -g mode-keys vi bind-key V copy-mode bind-key p paste-buffer bind-key -T copy-mode-vi 'v' send -X begin-selection bind-key -T copy-mode-vi 'y' send -X copy-selection-and-cancel
- Enter copy-mode with
prefix V - Begin selection by typing
v - Yank (copy) the selected text with
y - Then paste anywhere with
prefix p
3. Autostart tmux whenever ~/.bashrc is loaded
Using ~/.bashrc to start a tmux session or attach to an existing one
3.1. Single window
# Do not start tmux if inside Emacs and avoid nested tmux sessions if [[ -z $INSIDE_EMACS && -z $TMUX ]] then if [[ -n $DISPLAY || -n $WAYLAND_DISPLAY || -n $SSH_CONNECTION ]] then tmux new-session -A -s '0' -n cmd -c "$HOME" fi fi
3.2. Multiple windows
# Do not start tmux if inside Emacs and avoid nested tmux sessions if [[ -z $INSIDE_EMACS && -z $TMUX ]] then if [[ -n $DISPLAY || -n $WAYLAND_DISPLAY || -n $SSH_CONNECTION ]] then session_name='0' if tmux has-session -t "$session_name" then tmux attach-session -t "$session_name" else tmux new-session -d -s "$session_name" -n cmd -c "$HOME" tmux new-window -t "$session_name:1" -n rss 'newsboat --quiet' tmux new-window -t "$session_name:2" -n music -c "$HOME/music" 'cmus' tmux new-window -t "$session_name:3" -n framboise 'ssh framboise' tmux attach-session -t "$session_name" fi unset session_name fi fi
4. Autostart tmux whenever the fish shell is loaded
Add tmux_session at the end of ~/.config/fish/config.fish
tmux_session
4.1. Single window
# ~/.config/fish/functions/tmux_session.fish function tmux_session -d "Do not start tmux if inside Emacs and avoid nested tmux sessions" if test -z $INSIDE_EMACS and test -z $TMUX if test -n $DISPLAY or test -n $WAYLAND_DISPLAY or test -n $SSH_CONNECTION command new-session -A -s '0' -n cmd -c $HOME end end end
4.2. Multiple windows
# ~/.config/fish/functions/tmux_session.fish function tmux_session -d "Do not start tmux if inside Emacs and avoid nested tmux sessions" if test -z $INSIDE_EMACS and test -z $TMUX if test -n $DISPLAY or test -n $WAYLAND_DISPLAY or test -n $SSH_CONNECTION set -f session_name '0' if command tmux has-session -t $session_name command tmux attach-session -t $session_name else command tmux new-session -d -s $session_name -n cmd -c $HOME command tmux new-window -t $session_name:1 -n rss 'newsboat --quiet' command tmux new-window -t $session_name:2 -n music -c $HOME/music 'cmus' command tmux new-window -t $session_name:3 -n framboise 'ssh framboise' command tmux attach-session -t $session_name end end end end