Changes

Jump to navigation Jump to search
4,892 bytes added ,  3 years ago
Created initial page.
This page is for collecting various snippets and pieces for use with tmux.

=Quick cheat sheet of helpful tmux commands=
Source: <ref>https://gist.github.com/dusenberrymw/638359ea1ce409a2232375edb4a99948</ref>
# <code>tmux new</code> - Create and attach to a new session.
# <code>tmux new -s NAME_HERE</code> - Create and attach to a new session named NAME_HERE.
# <code>CTRL-b, d</code> - Detach (i.e. exit) from the currently-opened tmux session (alternatively, `tmux detach`). Note, this means press and hold `CTRL`, press `b`, release both, press `d`.
# <code>tmux ls</code> - Show list of tmux sessions.
# <code>tmux a</code> - Attach to the previously-opened tmux session.
# <code>tmux a -t NAME_HERE</code> - Attach to the tmux session named NAME_HERE.
# <code>CTRL-d</code> - Delete (i.e. kill) currently-opened tmux session (alternatively `tmux kill-session`).
# <code>CTRL-b, [</code> - Enter copy mode, and enable scrolling in currently-opened tmux session. Press `q` to exit.
# <code>CTRL-b, "</code> - Split window horizontally (i.e. split and add a pane below).
# <code>CTRL-b, %</code> - Split window vertically (i.e. split and add a pane to the right).
# <code>CTRL-b, UpArrow</code> - Move to the pane above (I prefer to rebind this to `CTRL-b, k` to be similar to Vim).
# <code>CTRL-b, DownArrow</code> - Move to the pane below (I prefer to rebind this to `CTRL-b, j` to be similar to Vim).
# <code>CTRL-b, LeftArrow</code> - Move to the pane to the left (I prefer to rebind this to `CTRL-b, h` to be similar to Vim).
# <code>CTRL-b, RightArrow</code> - Move to the pane to the right (I prefer to rebind this to `CTRL-b, l` to be similar to Vim).
# <code>CTRL-b, z</code> - Toggle maximization of current pane.
# <code>CTRL-b, ESC, 2</code> - Resize all panes to equal size.
# <code>CTRL-b, q</code> - Show pane numbers.
# <code>CTRL-b, x</code> - Kill current pane.
# <code>CTRL-b, c</code> - Create a new window.
# <code>CTRL-b, n</code> - Switch to next window.
# <code>CTRL-b, p</code> - Switch to previous window.
# <code>CTRL-b, 3</code> - Switch to window 3.
# <code>CTRL-b, CTRL-b, COMMAND</code> - Send the command to a nested tmux session (repeat prefix for each level of nesting).

=Configuration file additions=

==Alt arrow keys==
Use Alt-arrow keys without prefix key to switch panes<ref name="Reddit-1">https://www.reddit.com/r/tmux/comments/5cm2ca/post_you_favourite_tmux_tricks_here/d9y6jzu/?context=3</ref>

bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D

Shift + arrow keys to switch windows<ref name="Reddit-1" />

bind -n S-Left previous-window
bind -n S-Right next-window

==Zoom window==
Zoom Window - Useful for when you need to copy text out of a pane to your local clipboard without selecting text in other panes.<ref name="Reddit-1" />

unbind !
bind ! \
new-window -d -n tmux-zoom 'clear && echo TMUX ZOOM && read' \;\
swap-pane -s tmux-zoom.0 \;\
select-window -t tmux-zoom

unbind `
bind ` \
last-window \;\
swap-pane -s tmux-zoom.0 \;\
kill-window -t tmux-zoom

==Sync panes==
Sync panes (Send input to all panes in the window). When enabled, pane borders become red as an indication.<ref name="Reddit-1" />

bind-key y set-window-option synchronize-panes on \;\
set-window-option pane-active-border-style fg=red \;\
set-window-option pane-border-style fg=yellow \;\
display-message "Sync panes ON"
bind-key Y set-window-option synchronize-panes off \;\
set-window-option pane-active-border-style fg=green \;\
set-window-option pane-border-style default \;\
display-message "Sync panes OFF"

==Bash Multi Command (works with panes)==
Source: <ref name="Reddit-1" />

Works with tmux sync panes and spawns a new per argument and then sync them.

Useful for running ssh to multiple machines at same time, or issuing multiple commands at once.

Try it with:

multi ping 127.0.0.{1..10}

or

multi ssh server{1..5}

Configuration snippet:

function multi {
cmd=$1
shift
while [[ $cmd = "ssh" ]]; do
pre_check="$(echo $@ | tr ' ' '\n' | sed -e 's/^.*@//g' | \
xargs nmap -p 22 -PN -oG - | grep Port | grep -v open)"
test "${pre_check}x" != "x" && (clear; echo "$pre_check") || break
done
tmux send-keys -t 0 "$cmd ${@[1]}"
for ((pane = 1; pane < ${#@[@]}; pane++)); do
tmux splitw -h
tmux send-keys -t $pane "$cmd ${@[pane+1]}"
tmux select-layout tiled > /dev/null
done
tmux set-window-option synchronize-panes on > /dev/null
tmux set-window-option pane-active-border-style fg=red > /dev/null
tmux set-window-option pane-border-style fg=yellow > /dev/null
tmux send-keys Enter
}

=References=
<references />

Navigation menu