如何获取 tmux 中当前窗格下方窗格的索引?
How can I get the index of the pane underneath the current pane in tmux?
我正在尝试获取 tmux 中当前选定窗格正下方的窗格索引,以便我可以从 vim.
在该窗格上调用 tmux run-shell
假设我有一个如下所示的 tmux 面板布局:
|---------------------------|
| | |
| 0 | 1 |
| | |
|---------------------------|
| |
| 2 |
| |
|---------------------------|
我知道我可以通过 运行:
获取我当前的窗格编号
tmux list-panes | grep "active" | cut -d':' -f1
对于这种情况,我们会说它是 0
这是我想到的第一个获取索引的解决方案:
#!/bin/bash
CUR_PANE=$(tmux list-panes | grep "active" | cut -d':' -f1)
tmux select-pane -D
UNDER_PANE=$(tmux list-panes | grep "active" | cut -d':' -f1)
tmux select-pane -U
# In case the script is used on the bottom
# pane and `select-pane` wrapped around
if [ ! $UNDER_PANE -gt $CUR_PANE ]; then
echo "No pane under current."
exit 1
fi
echo $CUR_PANE
echo $UNDER_PANE
但这对我来说似乎是一种快速而肮脏的方法,因为我实际上必须 切换 到窗格,然后返回到原始窗格。
在不离开 tmux 中的当前窗格的情况下,是否有更简洁的方法来执行此操作?
我正在尝试获取 tmux 中当前选定窗格正下方的窗格索引,以便我可以从 vim.
在该窗格上调用tmux run-shell
假设我有一个如下所示的 tmux 面板布局:
|---------------------------|
| | |
| 0 | 1 |
| | |
|---------------------------|
| |
| 2 |
| |
|---------------------------|
我知道我可以通过 运行:
获取我当前的窗格编号tmux list-panes | grep "active" | cut -d':' -f1
对于这种情况,我们会说它是 0
这是我想到的第一个获取索引的解决方案:
#!/bin/bash
CUR_PANE=$(tmux list-panes | grep "active" | cut -d':' -f1)
tmux select-pane -D
UNDER_PANE=$(tmux list-panes | grep "active" | cut -d':' -f1)
tmux select-pane -U
# In case the script is used on the bottom
# pane and `select-pane` wrapped around
if [ ! $UNDER_PANE -gt $CUR_PANE ]; then
echo "No pane under current."
exit 1
fi
echo $CUR_PANE
echo $UNDER_PANE
但这对我来说似乎是一种快速而肮脏的方法,因为我实际上必须 切换 到窗格,然后返回到原始窗格。
在不离开 tmux 中的当前窗格的情况下,是否有更简洁的方法来执行此操作?