tmux是个十分好用的终端复用程序,常常使用服务器的男子伴可以将代码运行在服务器里的tmux的虚拟终端上,这样就毋须担忧由于自己笔记本的休眠或则意外断网而造成代码运行中断,因而损失掉自己跑了很长时间的实验结果。据悉配合配置文件,我们可以借助tmux在linux上像操作windows窗口或则浏览器窗口一样进行轻松的窗口多开和界定,还可以使用快捷键和滑鼠进行简单的图形化操作,使用体验绝佳。
下方显示了窗口数目,而且我这儿只开了一个(配合配置文件可以直接用键盘进行切换,十分便捷)
本想在实验室几个服务器上都装一个tmux,但鉴于实验室服务器没有给我sudo权限,难以使用apt-getinstalltmux一键安装。遍寻了网上的离线安装教程以后,我写了一个简单的shell脚本,下载解压到安装一步到位linux伊甸园,并手动添加了一个个人认为比较好用的配置文件,源码附在文章末尾了。
须要注意的是,添加默认配置文件后,tmux的prefix(默认的快捷键)从Ctrl+B变为了Ctrl+A!!!
须要注意的是,添加默认配置文件后,tmux的prefix(默认的快捷键)从Ctrl+B变为了Ctrl+A!!!
须要注意的是,添加默认配置文件后,tmux的prefix(默认的快捷键)从Ctrl+B变为了Ctrl+A!!!
重要的话说三遍,btw我认为Ctrl+A顺手多了。
但是该配置文件下一些窗口选择和大小调整的操作都可以用键盘直接点击或则拖动进行操作了。
脚本使用方式
首先在某个目录中新建一个.sh文件,并把源码复制进去
vim tmux_download_installer.sh
比如我这儿直接借助vim打开了tmux_download_installer.sh。随即按i打开insert模式,复制源码进去后按一下Escredhat linux 9.0,并输入:wq保存退出。
随即运行这个新建的.sh文件linux安装脚本,如下:
bash tmux_download_installer.sh
此后输入下载的压缩包储存路径和软件安装的目标文件夹路径(不须要带末尾的‘/’)linux安装脚本,等待片刻即可完成安装。
ps:bash前记得连网。
脚本源码(仅供参考)
# tmux_download_installer.sh
# download
read -p "Enter the Download path: " target_path
read -p "Enter the install path: " install_path
mkdir ${install_path}
wget -P ${target_path} https://github.com/libevent/libevent/releases/download/release-2.1.11-stable/libevent-2.1.11-stable.tar.gz
wget -P ${target_path} https://github.com/tmux/tmux/releases/download/3.0a/tmux-3.0a.tar.gz
wget -P ${target_path} https://ftp.gnu.org/gnu/ncurses/ncurses-6.2.tar.gz --no-check-certificate
# unzip
tar -xzvf ${target_path}/libevent-2.1.11-stable.tar.gz -C ${install_path}
tar -xzvf ${target_path}/ncurses-6.2.tar.gz -C ${install_path}
tar -xzvf ${target_path}/tmux-3.0a.tar.gz -C ${install_path}
#bevent
cd ${install_path}/libevent*
./configure --prefix=/my/path/tmux_depend --disable-shared
make && make install
#ncurses
cd ${install_path}/ncur*
./configure --prefix=/my/path/tmux_depend
make && make install
#tmux
cd ${install_path}/tmux*
./configure CFLAGS="-I/my/path/tmux_depend/include -I/my/path/tmux_depend/include/ncurses" LDFLAGS="-L/my/path/tmux_depend/lib -L/my/path/tmux_depend/include/ncurses -L/my/path/tmux_depend/include"
#CPPFLAGS="-I/my/path/tmux_depend//include -I/my/path/tmux_depend//include/ncurses" LDFLAGS="-static -L/my/path/tmux_depend//include -L/my/path/tmux_depend//include/ncurses -L/my/path/tmux_depend//lib"
# add config file
echo " " > ~/.tmux.conf
cat>~/.tmux.conf<<EOF
# Send prefix
set-option -g prefix C-a
unbind-key C-a
bind-key C-a send-prefix
# Use Alt-arrow keys to switch panes
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 to switch windows
bind -n S-Left previous-window
bind -n S-Right next-window
# Mouse mode
set -g mouse on
# Set easier window split keys
bind-key v split-window -h
bind-key h split-window -v
# Easy config reload
bind-key r source-file ~/.tmux.conf ; display-message "tmux.conf reloaded"
EOF
tmux source ~/.tmux.conf