Tmux Cheatsheet
Create session with a nameSESSION_NAME='mysession'tmux new -s "${SESSION_NAME}"Create detached ses 0001-1-1 08:0:0 Author: techvomit.net(查看原文) 阅读量:1 收藏

Create session with a name

SESSION_NAME='mysession'
tmux new -s "${SESSION_NAME}"

Create detached session with a name

This particular example will run SimpleHTTPServer in the background:

SESSION_NAME='python_sesh'
tmux new -s "${SESSION_NAME}" -d 'python3 -m http.server'

Kill tmux session programmatically

kill -9 "$(top -n 1 | pgrep tmux)"

Attach to session with name

SESSION_NAME='mysession'
tmux a -t "${SESSION_NAME}"
# Alternatively:
tmux attach -t "${SESSION_NAME}"

List sessions

# Outside of a tmux session:
tmux ls
# Within a tmux session:
Ctrl b s

Background session


Rename current session


Kill session

SESSION_NAME='ohno'
tmux kill-session -t "${SESSION_NAME}"

Background session on remote host and close ssh session

Resources: https://gist.github.com/henrik/1967800


Use tmuxinator for environment automation

Great tutorial here: https://collectiveidea.com/blog/archives/2017/03/27/using-tmuxinator-to-automate-your-environment


Use mouse to copy and paste in a pane

In iTerm2:

  1. Hold down the Option key and the alt key
  2. Drag your mouse with the left click to select a body of text in a particular pane

Use Ctrl c to copy and Ctrl v to paste.

If on a mac:

Resource: https://stackoverflow.com/questions/12287432/how-to-copy-to-system-clipboard-from-tmux-output-after-mouse-selection


This particular example will show the help menu for Ctrl b t, which will display the current time:

tmux_clock


Type this command in:

At this point you can use your arrow keys, page up/page down, etc.

Resource: https://superuser.com/questions/209437/how-do-i-scroll-in-tmux


Screen splitting

Horizontal split:

Vertical split:

Change direction of split:

Resources: https://gist.github.com/MohamedAlaa/2961058

Change starting dir of new tmux session

  1. Detach from the tmux session
  2. Run this command:
SESSION_NAME='mysession'
NEW_START_DIR='/home/ubuntu/somewhere'
tmux attach-session -t "${SESSION_NAME}" -c "${NEW_START_DIR}"

Resource: https://stackoverflow.com/questions/27307815/how-to-change-the-starting-directory-of-a-tmux-session

Detach from nested tmux session

Resource: https://superuser.com/questions/249659/how-to-detach-a-tmux-session-that-itself-already-in-a-tmux

Paste

Reload tmux config

tmux source-file ~/.tmux.conf

Add this to your dotfiles so you can run it for all panes:

source_tmux_conf() {
    session=`tmux display-message -p "#S"`

    for pane in $(tmux list-panes -s -F "#{pane_id}"); do
        tmux send-keys -t $session.$pane "tmux source-file ~/.tmux.conf" C-m
    done
}

文章来源: https://techvomit.net/tmux-cheatsheet/
如有侵权请联系:admin#unsafe.sh