【发布时间】:2016-01-26 14:39:45
【问题描述】:
我有一个 .tmux.conf,我在安装了不同 tmux 版本的不同机器上使用它。
我想根据 tmux 版本设置不同的鼠标选项。
在一台机器上我有版本2.0 另一台2.1。
我不明白他的角色
if "[[(( $(tmux -V | cut -c 6-) < 2.1 ))]]" \
"set -g mode-mouse on;" \
"set -g mouse-resize-pane on;" \
"set -g select-pane on;" \
"set -g select-window on" "set -g mouse on"
当我获取文件时
$ tmux source-file .tmux.conf
我收到这条消息
.tmux.conf:12: unknown command: set -g mouse-resize-pane on
我运行它的机器版本为2.1,所以它不应该设置四个选项。
我想在运行 tmux 2.0 或更低版本时设置四个选项,或者在运行 tmux 2.1 时设置一个选项。
这个 bash 语句有效
$ tmux -V
tmux 2.1
$ if [[(( $(tmux -V | cut -c 6-) < 2.1 ))]];then echo $?;else echo $?;fi
1
【问题讨论】:
-
为什么你在那个测试中同时拥有
[[ ]]和(( ))?我认为只要(( ))就足够了,假设if(即if-shell?)测试返回码。 -
将 if 语句修复为
if "(( $(tmux -V | cut -c 6-) < 2.1 ))" "set -g mode-mouse on; set -g mouse-resize-pane on; set -g select-pane on; set -g select-window on"解决了问题,您能否发表评论作为答案。 -
实际上
(( ))无法处理十进制数字,因此如果可行,那是另一个原因(或意外)。 tmux 有办法测试功能吗? (我假设您只希望在支持它的版本中打开它。) -
我不知道tmux是否可以测试功能,我对tmux比较陌生。
标签: bash shell if-statement scripting tmux