
현재 운영 체제를 기반으로 Tmux 명령을 어떻게 실행할 수 있나요?
Linux와 macOS 모두에서 동일한 Tmux 구성 파일을 사용하고 싶지만 Tmux를 시스템 클립보드와 통합하는 것과 같은 일부 구성은 플랫폼 간에 이식 가능하지 않습니다.
명령 에 대해 읽었 if-shell
지만 일부 리소스에서는 이것이 비동기 작업(백그라운드에서 실행됨)이라고 말하므로 세션이 제대로 구성되지 않을 가능성이 높습니다(왜?).
~/.tmux.conf:
# vim copy to system clipboard
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"
답변1
Tmux에서 현재 운영 체제(Linux 또는 macOS)를 기반으로 조건부 명령을 실행합니다.
# vim copy to system clipboard
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"
}
if-shell
백그라운드에서 -b
실행되는 옵션( )을 지원합니다 . shell-command
기본적으로 즉시 실행됩니다.
if-shell [-bF] [-t target-pane] shell-command command [command]
(alias: if)
Execute the first command if shell-command returns success or the second command otherwise. Before being executed, shell-command is expanded using the rules specified in the FORMATS section,
including those relevant to target-pane. With -b, shell-command is run in the background.
또한 ( man tmux
):
Commands like if-shell, run-shell and display-panes stop execution of subsequent commands on the queue until something happens - if-shell and run-shell until a shell command finishes and display-panes until a key is pressed. For example, the following commands:
new-session; new-window
if-shell "true" "split-window"
kill-session
Will execute new-session, new-window, if-shell, the shell command true(1), split-window and kill-session in that order.