tmux if

编程入门 行业动态 更新时间:2024-10-25 16:21:02
本文介绍了tmux if-shell run-shell 不同的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

下面的 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/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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 05:05:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1390137.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:tmux

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!