Tmux | 玩机
本文最后更新于:2021年4月8日
Install tmux on rhel/centos 7
# install deps
yum install -y kernel-devel ncurses-devel
# download sources for libecent and make and install
curl -OL https://github.com/libevent/libevent/releases/download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz
tar -xvzf libevent-2.0.22-stable.tar.gz
cd libevent-2.0.22-stable
./configure --prefix=/usr/local
make -j`nproc`
make install
cd ..
# download sources for tmux and make and install
curl -OL https://github.com/tmux/tmux/releases/download/2.3/tmux-2.3.tar.gz
tar -xvzf tmux-2.3.tar.gz
cd tmux-2.3
LDFLAGS="-L/usr/local/lib -Wl,-rpath=/usr/local/lib" ./configure --prefix=/usr/local
make -j`nproc`
make install
cd ..
# open new shell and check tmux version
tmux -V
层次结构
tmux 的主要元素分为三层(从小到大):
- pane:窗格,被划分成小块的窗口
- window:单个可见窗口,概念类似 tab
- session:一组窗口的集合,通常用来概括同一个任务,session 可以有自己的名字便于任务之间的切换。
基本操作
在 tmux 会话中使用的快捷键都需要一个前缀来激活,前缀默认为 ctrl+b(即在按快捷键之前需要按一下前缀,下文用 PREFIX: 指代)
- 查询所有会话
tmux ls
- 创建会话
tmux new -s $session_name
- 断开会话(断开会话并不影响会话中运行的程序,断开后还可以重新连接)
tmux detach
# 或者使用快捷键 ctrl+b d(即先使用 ctrl+b 快捷键前缀,然后再按 d)
# 或者使用快捷键 ctrl+b ctrl+z
- 重新连接会话
tmux attach -t $session_name
- 关闭会话(会话中的程序也会全部关闭)
tmux kill-session -t $session_name
# 或者使用快捷键 ctrl+b d
快捷键
配置
在 ~/.tmux.conf 中加入配置,修改后不会立即生效,需要重启 tmux 或者在命令模式(按 PREFIX:)输入 source-file ~/.tmux.conf
- 更改前缀命令
set -g prefix C-x
unbind C-b
- 打开鼠标模式(该功能在 2.x 及以上版本中才有)
set-option -g mouse on
- 在当前目录打开新窗口
bind '"' split-window -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}"
bind c new-window -c "#{pane_current_path}"
- 取消历史共享(直接在终端中执行)
setopt noincappendhistory
setopt nosharehistory
评论系统采用 utterances ,加载有延迟,请稍等片刻。