tmux.conf 中嵌套 if 或嵌套引号的问题

Problem in tmux.conf with nested if or nested quotes

我通过 ssh 连接到具有共享配置文件但 tmux 版本不同的机器,因此我尝试让单一版本感知。tmux.conf。以下是我的 tmux 2.6 机器。

我的问题似乎是嵌套的 ifs,或者可能是嵌套的引号。

只有一个 window 存在时,以下代码隐藏状态栏:

if -F '#{==:#{session_windows},1}' 'set -g status off' 'set -g status on'; \
set-hook -g window-linked 'if -F "#{==:#{session_windows},1}" "set -g status off" "set -g status on"'; \
set-hook -g window-unlinked 'if -F "#{==:#{session_windows},1}" "set -g status off" "set -g status on"'; 

但是我的版本保护在单引号字符串周围添加了双引号,打破了这个

if-shell -b '[ "$(echo "$TMUX_VERSION >= 2.1" | bc)" = 1 ]' " \
if -F '#{==:#{session_windows},1}' 'set -g status off' 'set -g status on'; \
set-hook -g window-linked 'if -F "#{==:#{session_windows},1}" "set -g status off" "set -g status on"'; \
set-hook -g window-unlinked 'if -F "#{==:#{session_windows},1}" "set -g status off" "set -g status on"'; \
"

tmux 启动没有任何错误,但状态栏没有隐藏。

您需要将 " 转义到其他 " 中作为 \"

或者将您的内部命令放在一个单独的配置文件中并使用 source-file 加载它。

如果你使用的是更高版本的 tmux,你可以使用 {} 来避免这个问题,但在旧的 tmux 版本上你需要转义引号。