tmux if-shell 运行-shell 不同的输出
tmux if-shell run-shell different outputs
下面的 is_vim
命令与 tmux if-shell
命令一起使用,以正确检测 vim 是否在当前窗格中打开,如果是,则发送下面的键命令。
但是,它不适用于 run-shell
,我不确定为什么。使用 run-shell
,if 语句似乎总是评估为 false,它总是调用下面的 tmux select-pane 命令。
# is_vim is directly from the setup guide for https://github.com/christoomey/vim-tmux-navigator
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\S+\/)?g?(view|n?vim?x?)(diff)?$'"
# Comment out one of the below to test
bind -n C-l if-shell "$is_vim" "send-keys C-l" "select-pane -R"
bind -n C-h run-shell "if [ $is_vim ]; then tmux send-keys C-l; else tmux select-pane -R; fi"
[
是一个命令,不是 if
语法的一部分。展开后,你有
if [ ps -o ... | grep ... ]; then
这是错误的;你只要
if ps -o ... | grep ...; then
所以去掉括号:
bind -n C-h run-shell "if $is_vim ; then tmux send-keys C-l; else tmux select-pane -R; fi"
但是,您应该可以做一些更简单的事情(未测试):
bind -n C-l if-shell "[ #{pane_current_command} = vim ]" ...
bind -n C-h run-shell "if [ #{pane_current_command} = vim ]; then ..."
#{pane_current_command}
在 shell 看到命令之前扩展了 tmux
。
下面的 is_vim
命令与 tmux if-shell
命令一起使用,以正确检测 vim 是否在当前窗格中打开,如果是,则发送下面的键命令。
但是,它不适用于 run-shell
,我不确定为什么。使用 run-shell
,if 语句似乎总是评估为 false,它总是调用下面的 tmux select-pane 命令。
# is_vim is directly from the setup guide for https://github.com/christoomey/vim-tmux-navigator
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\S+\/)?g?(view|n?vim?x?)(diff)?$'"
# Comment out one of the below to test
bind -n C-l if-shell "$is_vim" "send-keys C-l" "select-pane -R"
bind -n C-h run-shell "if [ $is_vim ]; then tmux send-keys C-l; else tmux select-pane -R; fi"
[
是一个命令,不是 if
语法的一部分。展开后,你有
if [ ps -o ... | grep ... ]; then
这是错误的;你只要
if ps -o ... | grep ...; then
所以去掉括号:
bind -n C-h run-shell "if $is_vim ; then tmux send-keys C-l; else tmux select-pane -R; fi"
但是,您应该可以做一些更简单的事情(未测试):
bind -n C-l if-shell "[ #{pane_current_command} = vim ]" ...
bind -n C-h run-shell "if [ #{pane_current_command} = vim ]; then ..."
#{pane_current_command}
在 shell 看到命令之前扩展了 tmux
。