嵌套 if 命令或 if 在 tmux 中有两个条件

Nested if command or if with two conditions in tmux

我正在尝试为要测试 tmux 版本和操作系统的复制命令编写绑定。如果 tmux 版本低于 2.4 并使用 Linux 做一件事,使用 Mac 做另一件事,对于高于 2.4 的版本则相同。

如果Linux:

if-shell -b '[ "$(echo "$TMUX_VERSION < 2.4" | bc)" = 1 ]' " \
    bind-key -t vi-copy y   copy-pipe 'xclip -selection clipboard -in'" " \
    bind-key -T copy-mode-vi y   send -X copy-pipe-and-cancel 'xclip -selection clipboard -in'"

如果Mac:

if-shell -b '[ "$(echo "$TMUX_VERSION < 2.4" | bc)" = 1 ]' " \
    bind-key -t vi-copy 'y' copy-pipe "reattach-to-user-namespace pbcopy" " \
    bind -Tcopy-mode-vi 'y' send -X copy-pipe-and-cancel 'tmux save-buffer - | reattach-to-user-namespace pbcopy'"

您可以在测试中使用 -a

if '[ "blah" = 1 -a "$(uname)" = Linux ]' ...

或者 if-shell 的每个参数都是一个 tmux 命令,因此您可以嵌套它们:

if 'true' 'if "true" "whatever"'