if-shell
当在 中使用 Tmux 的命令时tmux.conf
,我最终会得到非常长的命令,如下所示,用于将 Tmux 与 macOS 和 Linux 上的系统剪贴板集成:
if-shell "[[ $(uname -s) = Linux ]]" "bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel \"pbcopy\"" "bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel \"xclip -in -selection clipboard\""
是否可以将命令写入tmux.conf
多行?我尝试使用\
跨越多行,但它不起作用。
答案1
根据man tmux
:
每个命令均以换行符或分号 (;) 结尾。
因此,看起来似乎不是在命令中插入换行符。
但是,命令参数可能包含换行符,可用于将命令跨越多行:
' ... \
或者" ... \
:
If the last character of a line is \, the line is joined with the following line (the \ and the newline are completely removed).
( { ... }
):
Braces are similar to single quotes in that the text inside is taken literally without any replacements but this also includes line continuation.
例子:
if-shell '[[ $(uname -s) = Linux ]]' {
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xclip -in -selection clipboard"
} {
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy"
}