在我的本地机器上,我同时运行了3个node.js实例。每一个都在一个叫做“服务器”的tmux窗口中有它自己的窗格。问题是,找出哪个节点在哪个窗格中运行并不是那么容易,因为它们的日志是相似的。
我需要的是每个窗格的标题。据我所知,tmux本身没有这个功能:它只有窗口的标题,没有窗格的标题。在每个窗格中为每个node.js实例启动单独的tmux会话看起来有点过头了。
那么,有没有一些小程序可以启动命令,用指定的状态栏包装其输出呢?
提前感谢
发布于 2012-03-18 17:00:13
tmux确实支持每个窗格的标题,但它不提供每个窗格的位置来显示这些标题。
可以使用转义序列ESC ]2;…设置窗格的标题ESC \ (例如,请参阅tmux手册页中的名称和标题部分)。您可以像这样从shell中执行此操作:
printf '\033]2;%s\033\\' 'title goes here'每个窗格的标题默认为系统的主机名。缺省情况下,活动窗格的标题显示在tmux状态行的右侧(会话变量status-right的缺省全局值是"#22T" %H:%M %d-%b-%y,它显示窗格标题、时间和日期的22个字符)。
因此,只要您对能够看到活动窗格的标题感到满意(即,愿意切换窗格以查看非活动窗格的标题),您就可以使用默认功能。只需在启动每个窗格的主命令之前发送适当的标题设置转义序列即可。
如果您绝对需要一条专用线路来显示某些每个窗格的信息,那么嵌套的tmux会话可能不会像您最初认为的那样“过度杀伤力”。
在一般情况下,为了在某些给定的终端上提供不可侵犯的状态行,您将需要一个位于原始终端和新终端之间的完整的终端(Re)仿真器(具有较少一行的终端)。需要这样的(重新)仿真来翻译发送到内部终端的控制序列,并为原始终端翻译它们。例如,要在外部终端的底部维护状态行,命令
移到最后一行。
发送到内部终端必须变成
移到倒数第二行。
当被翻译并发送到外部终端时。同样,发送到内部终端的LF必须变为
如果光标位于倒数第二行,则将此行及其上方的所有行向上滚动一行,以提供清晰的倒数第二行(保护最后一行上的状态行)。否则,发送LF。
在外部终端。
像tmux和screen这样的程序就是这样的终端再仿真器。当然,围绕终端仿真器还有许多其他功能,但您需要大量的终端仿真代码才能提供可靠的状态行。
然而,有一个轻量级的解决方案,只要
与许多终端仿真器一样,tmux在其窗格中支持“设置滚动区域”终端控制命令。您可以使用此命令将滚动区域限制在终端的顶部(或底部) 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"您可以这样使用它:
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'只要终端支持并发布其csr和cup terminfo能力,该脚本也应该在tmux之外工作。
发布于 2016-06-03 05:02:27
此功能已添加到this commit中的tmux中。它不在版本2.2中,但看起来将在2.3中。
要启用它,请执行以下操作:
tmux set -g pane-border-status top或者,如果您愿意:
tmux set -g pane-border-status bottom要将自定义文本设置为窗格边框状态行,您可以使用pane-border-format,例如:
tmux set -g pane-border-format "#{pane_index} #{pane_current_command}"发布于 2019-04-25 17:25:23
使用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您可以使用以下命令在状态栏中查看每个窗格的标题:
$ tmux set pane-border-status bottom # For current window
$ tmux set -g pane-border-status bottom # For all windows使用以下命令禁用状态栏:
$ tmux set pane-border-status off # For current window
$ tmux set -g pane-border-status off # For all windowshttps://stackoverflow.com/questions/9747952
复制相似问题