Skip to content

Instantly share code, notes, and snippets.

@rambolee
Last active December 21, 2020 05:33
Show Gist options
  • Save rambolee/cca2837a62ca83ed12c5a65fe5e9272f to your computer and use it in GitHub Desktop.
Save rambolee/cca2837a62ca83ed12c5a65fe5e9272f to your computer and use it in GitHub Desktop.
升级配置安装 tmux 遇到的问题

升级配置安装 tmux 遇到的问题

升级tmux的起因: 因为使用下面tmux相关维护脚本时,发现1.8.*的版本的tmux在一些参数支持上不到位。 该脚本很多信息保留不全,导致使用效果不好。所以,需要放弃centos自身yum源中的tmux,然后自己手工source.tar.gz进行安装。

脚本参考: https://segmentfault.com/a/1190000000457385#articleHeader0

tmux 相关脚本

tmuxEnvSaver.sh

#!/bin/bash
tmuxSnapshot=/.tmux_snapshot
tmuxEXE=/usr/local/bin/tmux
save_snap()
{
        ${tmuxEXE} list-windows -a -F"#{session_name} #{window_name} #{pane_current_command} #{pane_current_path}" > ${tmuxSnapshot}
}

restore_snap()
{
        ${tmuxEXE} start-server
        while IFS=' ' read -r session_name window_name pane_current_command pane_current_path
        do
                ${tmuxEXE} has-session -t "${session_name}" 2>/dev/null
                if [ $? != 0 ]
                then
                        ${tmuxEXE} new-session -d -s "${session_name}" -n ${window_name}
                else
                        ${tmuxEXE} new-window -d -t ${session_name} -n "${window_name}"
                fi
                ${tmuxEXE} send-keys -t "${session_name}:${window_name}" "cd ${pane_current_path}; echo \"Hint: last time you are executing '${pane_current_command}'.\"" ENTER
        done < ${tmuxSnapshot}
}

ps aux|grep -w tmux|grep -v grep
if [ $? != 0 ]
then
        restore_snap
else
        save_snap
fi

——————————————

crontab

* * * * * echo "`date`: tmuxEnvSaver is running" >> /tmp/cron-tmux.log 2>&1
* * * * * /root/tmuxEnvSaver.sh >> /tmp/cron-tmux.log 2>&1
@reboot /root/tmuxEnvSaver.sh >> /tmp/cron-tmux.log 2>&1

===================

itmux.sh

#!/bin/sh

TMUX="/usr/local/bin/tmux"

$TMUX has-session -t default

if [ $? = 1 ]; then
    echo "$TMUX new-session -s default"
    $TMUX new-session -s default
else
    echo "$TMUX attach-session -d -t default"
    $TMUX attach-session -d -t default
fi

安装最新版tmux

前提yum install libevent2

ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5
git clone https://github.com/tmux/tmux.git
cd tmux
sh autogen.sh
export LIBEVENT_CFLAGS="-I/usr/local/include" export LIBEVENT_LIBS="-L/usr/local/lib -Wl,-rpath=/usr/local/lib -levent" 
./configure && make

备注:

如果出现 “protocol version mismatch (client 8, server 6)” 类似这样的错误,说明系统中之前存在别的tmux进程是不同的版本的程序生成的,需要先前内存中的tmux进程kill掉。

配置脚本

setw -g mode-keys vi
setw -g aggressive-resize on
setw -g mouse on

开启mouse模式之后,选择文本需要使用shift

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment