Tmux安裝和使用


1、What's tmux

tmux 是一個終端復用器: 可以激活多個終端或窗口, 在每個終端都可以單獨訪問,每一個終端都可以訪問,運行和控制各自的程序.tmux類似於screen,可以關閉窗口將程序放在后台運行,需要的時候再重新連接。

2、How to install tmux

如果你創建的是workspace,那么已經安裝好了tmux,如果你想全新安裝tmux,只需要執行:

sudo apt-get install -y tmux

3、配置tmux

3.1、編輯 ~/.tmux.conf 文件,添加下面代碼

set -sg escape-time 0
set-option -g history-limit 30000
# set-option -g default-shell /bin/zsh  # 使用 zsh 為默認 shell
set-window-option -g mode-keys vi # vi key
set-option -g status-keys vi
set -g default-terminal "tmux-256color"
  
# vim-like pane selection
bind l select-pane -R
bind j select-pane -D
bind k select-pane -U
bind h select-pane -L
  
bind -r c-h resize-pane -L 5
bind -r c-j resize-pane -D 1
bind -r c-k resize-pane -U 1
bind -r c-l resize-pane -R 5
  
# 在當前目錄創建新窗口
unbind-key c
bind c new-window -c "#{pane_current_path}"
unbind-key '"'
unbind-key '%'
bind '"' split-window -c '#{pane_current_path}'
bind '%' split-window -h -c '#{pane_current_path}'
# end
  
set -g base-index 1 # start windows numbering at 1
setw -g pane-base-index 1 # make pane numbering consistent with windows
set-option -g update-environment "DBUS_SESSION_BUS_ADDRESS DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY"
  
# 顯示工作區標題
set -g pane-border-status top
set -g pane-border-format "#{pane_index} #T"

3.2、重新導入tmux配置環境

tmux source ~/.tmux.conf

4、如何讓zsh標題為目錄名?

編輯 ~/.zshrc 加入如下代碼段:

function set_tmux_title () {
    printf '\033]2;'"$1"'\033\\'
}
  
function auto_tmux_title() {
    emulate -L zsh
    printf '\033]2;'"${PWD:t}"'\033\\'
}
  
auto_tmux_title
chpwd_functions=(${chpwd_functions[@]} "auto_tmux_title")

tmux cheat sheet
https://gist.github.com/ryerh/14b7c24dfd623ef8edc7


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM