tmux如果shell运行shell不同的输出

tmux如果shell运行shell不同的输出,shell,tmux,Shell,Tmux,下面的is_vim命令与tmuxif shell命令一起工作,以正确检测当前窗格中的vim是否打开,如果打开,则发送下面的键命令 # 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?

下面的
is_vim
命令与tmux
if shell
命令一起工作,以正确检测当前窗格中的vim是否打开,如果打开,则发送下面的键命令

# 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"
但是,它不适用于
运行shell
,我不知道为什么。使用
runshell
,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"
但是,您应该能够做一些更简单的事情(未经测试):


{pane\u current_command}
在shell看到命令之前展开
tmux

谢谢;我不记得
tmux
是否有自己的条件构造。