tmux if-shell run-shell 不同的输出 [英] tmux if-shell run-shell different outputs

查看:38
本文介绍了tmux if-shell run-shell 不同的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

The is_vim command below works with the tmux if-shell command to properly detect if vim is open in the current pane, and if so then sends the key command below.

但是,它不适用于 run-shell,我不知道为什么.使用 run-shell,if 语句似乎总是评估为 false,它总是调用下面的 tmux select-pane 命令.

But, it is not working with run-shell, and I'm not sure why. With run-shell, the if statement always seems to evaluate to false and it always called the tmux select-pane command below.

# 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 语法的一部分.展开后,你有

[ is a command, not part of if's syntax. After expansion, you have

if [ ps -o ... | grep ... ]; then

这是错误的;你只是想要

which is wrong; you just want

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"

但是,您应该能够做一些更简单的事情(未经测试):

However, you should be able to do something simpler (not tested):

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 展开.

#{pane_current_command} is expanded by tmux before the shell sees the command.

这篇关于tmux if-shell run-shell 不同的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆