
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"
}