![是否可以将 tmux.conf 中的命令拆分为多行?](https://linux22.com/image/178370/%E6%98%AF%E5%90%A6%E5%8F%AF%E4%BB%A5%E5%B0%86%20tmux.conf%20%E4%B8%AD%E7%9A%84%E5%91%BD%E4%BB%A4%E6%8B%86%E5%88%86%E4%B8%BA%E5%A4%9A%E8%A1%8C%EF%BC%9F.png)
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"
}