And*_*kov 73 command-line title pane tmux
在我的本地机器上,我有3个node.js实例同时运行.每个窗口都在一个名为"servers"的tmux窗口中拥有自己的窗格.问题是找出哪个节点在哪个窗格中运行并不容易,因为它们的日志类似.
我需要的是每个窗格的标题.正如我所知,tmux本身没有这个功能:它只有窗口的标题而不是窗格.在每个窗格内为每个node.js实例启动单独的tmux会话看起来像是一种过度杀伤.
那么是否有一些小程序启动命令,用指定的状态栏包装其输出?
提前致谢
Chr*_*sen 74
tmux确实支持每个窗格的标题,但它不提供显示这些标题的每个窗格位置.
您可以使用转义序列ESC ]2;
... ESC 设置窗格的标题\
(例如,请参阅tmux联机帮助页中的名称和标题部分).你可以从shell这样做:
printf '\033]2;%s\033\\' 'title goes here'
Run Code Online (Sandbox Code Playgroud)
每个窗格的标题默认为系统的主机名.默认情况下,活动窗格的标题显示在右侧TMUX状态行(会话变量的默认全局值status-right
是"#22T" %H:%M %d-%b-%y
,这显示了窗格的标题,时间为22个字符,日期).
所以,只要您满意能够看到活动窗格的标题(即愿意转换窗格看到一个非活动窗格的标题),你可以使用默认的功能得到通过.只需在为每个窗格启动main命令之前发送相应的标题设置转义序列.
如果你绝对需要一个专用线,以显示一定的每窗格信息,然后嵌套TMUX会话可能不会这么大(不要)"矫枉过正",你可能首先想到.
在一般情况下,要在某个给定终端上提供inviolate状态行,您将需要一个位于原始终端和新终端(一个少一行的终端)之间的完整终端(重新)仿真器.需要这种(重新)仿真来转换发送到内部终端的控制序列并将它们转换为原始终端.例如,要在外部终端的底部维护状态行,请执行命令
移到最后一行.
发送到内部终端必须成为
移到下一行到最后一行.
当翻译并发送到外部终端时.同样,发送到内部终端的LF必须成为
如果光标位于倒数第二行,则将此行及其上方的所有行向上滚动一行,以提供明确的倒数第二行(保护最后一行的状态行).否则,发送一个LF.
在外部终端.
像tmux和screen这样的程序就是这样的终端重模拟器.当然,终端仿真器周围还有许多其他功能,但您需要大量的终端仿真代码才能提供可靠的状态行.
然而,只要有轻量级的解决方案
与许多终端仿真器一样,tmux在其窗格中支持"set scrolling region"终端控制命令.你可以使用该命令来滚动区域限制到顶部(或底部)的终端的N-1线和写某种实例识别文本的进入非滚动线.
的限制(没有光标移动命令允许的,未调整大小)是必需的,因为这是产生输出(例如,一个程序的Node.js实例)具有不知道滚动被限制到特定的区域.如果输出生成程序碰巧将光标移动到滚动区域之外,则输出可能变为乱码.同样,当终端调整大小时,终端仿真器可能会自动重置滚动区域(因此"非滚动线"可能最终会滚动离开).
我编写了一个脚本,用于tput
生成适当的控制序列,写入非滚动行,并在将光标移动到滚动区域后运行程序:
#!/bin/sh
# usage: no_scroll_line top|bottom 'non-scrolling line content' command to run with args
#
# Set up a non-scrolling line at the top (or the bottom) of the
# terminal, write the given text into it, then (in the scrolling
# region) run the given command with its arguments. When the
# command has finished, pause with a prompt and reset the
# scrolling region.
get_size() {
set -- $(stty size)
LINES=$1
COLUMNS=$2
}
set_nonscrolling_line() {
get_size
case "$1" in
t|to|top)
non_scroll_line=0
first_scrolling_line=1
scroll_region="1 $(($LINES - 1))"
;;
b|bo|bot|bott|botto|bottom)
first_scrolling_line=0
scroll_region="0 $(($LINES - 2))"
non_scroll_line="$(($LINES - 1))"
;;
*)
echo 'error: first argument must be "top" or "bottom"'
exit 1
;;
esac
clear
tput csr $scroll_region
tput cup "$non_scroll_line" 0
printf %s "$2"
tput cup "$first_scrolling_line" 0
}
reset_scrolling() {
get_size
clear
tput csr 0 $(($LINES - 1))
}
# Set up the scrolling region and write into the non-scrolling line
set_nonscrolling_line "$1" "$2"
shift 2
# Run something that writes into the scolling region
"$@"
ec=$?
# Reset the scrolling region
printf %s 'Press ENTER to reset scrolling (will clear screen)'
read a_line
reset_scrolling
exit "$ec"
Run Code Online (Sandbox Code Playgroud)
您可以像这样使用它:
tmux split-window '/path/to/no_scroll_line bottom "Node instance foo" node foo.js'
tmux split-window '/path/to/no_scroll_line bottom "Node instance bar" node bar.js'
tmux split-window '/path/to/no_scroll_line bottom "Node instance quux" node quux.js'
Run Code Online (Sandbox Code Playgroud)
只要终端支持并发布其和terminfo功能,该脚本也应该在tmux之外工作.csr
cup
kev*_*tch 64
此提交已将此功能添加到tmux git中.它不是在2.2版本中,但看起来它将在2.3中.
要启用它:
tmux set -g pane-border-status top
Run Code Online (Sandbox Code Playgroud)
或者如果您愿意:
tmux set -g pane-border-status bottom
Run Code Online (Sandbox Code Playgroud)
要将自定义文本设置为窗格边框状态行,您可以使用pane-border-format
,例如:
tmux set -g pane-border-format "#{pane_index} #{pane_current_command}"
Run Code Online (Sandbox Code Playgroud)
Eya*_*vin 16
由于tmux 2.6
您可以:
$ tmux select-pane -t {pane} -T {title}
# Examples:
$ tmux select-pane -T title1 # Change title of current pane
$ tmux select-pane -t 1 -T title2 # Change title of pane 1 in current window
$ tmux select-pane -t 2.1 -T title3 # Change title of pane 1 in window 2
Run Code Online (Sandbox Code Playgroud)
您可以在状态栏中查看每个窗格的标题,其中包括:
$ tmux set pane-border-status bottom # For current window
$ tmux set -g pane-border-status bottom # For all windows
Run Code Online (Sandbox Code Playgroud)
通过以下方式禁用状态栏:
$ tmux set pane-border-status off # For current window
$ tmux set -g pane-border-status off # For all windows
Run Code Online (Sandbox Code Playgroud)
Jon*_*ers 14
我正在处理tmux - ticket的窗格状态栏.我的开发分支可以在github上找到:https: //github.com/jonathanslenders/tmux
现在,这已经添加了一个有效的重命名窗格"标题"命令.仍然存在一些错误,API将会改进.我们的想法是为每个窗格创建一个状态栏,它可以有一些格式,例如会话状态栏.与tmux的其余部分一样,一切都应该是可编写脚本的,并且可以自定义.完成并稳定后,它可能会包含在官方tmux中.
小智 12
我使用的是tmux 2.3版,我认为以前的版本不支持边框样式.这对我有用:
为每个窗格设置标题:
printf '\033]2;My Pane Title\033\\'
Run Code Online (Sandbox Code Playgroud)
然后:
tmux set -g pane-border-format "#{pane_index} #T"
Run Code Online (Sandbox Code Playgroud)
nav*_*aid 10
gif价值一千个单词。(来源)
tmux-xpanes是基于tmux的终端分隔符,它支持通过新添加的-t
选项显示每个窗格的标题。
是的,有这样一个命令:tmux
.为您的会话命名,它将显示在内部状态栏中:
TMUX=0 tmux new-session -s my-new-session
Run Code Online (Sandbox Code Playgroud)
在里面添加这三行.tmux.conf
是有效的,并且不会干扰pane_title
tmux 管理的变量
set -g pane-border-status top
set -g pane-border-format "#[fg=black, bg=green] #{pane_index} #{@custom_pane_title}"
bind < command-prompt -p "New Title: " -I "#{@custom_pane_title}" "set-option -p @custom_pane_title '%%'"
Run Code Online (Sandbox Code Playgroud)
添加这些行后,使用 source.tmux.conf
来反映更改
tmux source-file ~/.tmux.conf
Run Code Online (Sandbox Code Playgroud)
在 tmux 窗格中,按Ctrl+B <
,输入您选择的标题,窗格标题将被设置。
窗格标题可以从多个来源设置,我想避免对其产生任何干扰。
参考:https://gist.github.com/ethagnawl/db27bba3c4cccdc30ade2a0c54f49723
长话短说
将以下配置附加到您的 tmux 配置文件(在我的例子中是~/.tmux.conf.local
)
# dispaly pane_current_path as the pane title
set -g pane-border-status top
set -g pane-border-format "#{pane_index} #{pane_current_path}"
Run Code Online (Sandbox Code Playgroud)
然后运行:
tmux source-file ~/.tmux.con
Run Code Online (Sandbox Code Playgroud)
好好享受