如何自定义 tmux“最后一个窗口标记”?

Yat*_*ima 5 tmux

默认情况下,Tmux 显示-在窗口标题之后,以表示上次访问的窗口。有没有办法自定义此标记并将其设置为自定义符号?谢谢,

Kam*_*ski 8

man 1 tmux说:

\n\n
\n

默认情况下,窗口列表按数字升序显示当前会话中存在的窗口的索引、名称和(如果有)标志。它可以使用window-status-formatwindow-status-current-format选项进行定制。该标志是附加到窗口名称的以下符号之一:

\n\n
Symbol    Meaning\n*         Denotes the current window.\n-         Marks the last window (previously selected).\n#         Window is monitored and activity has been detected.\n!         A bell has occurred in the window.\n~         The window has been silent for the monitor-silence interval.\nM         The window contains the marked pane.\nZ         The window\'s active pane is zoomed.\n
Run Code Online (Sandbox Code Playgroud)\n
\n\n

关于set-window-option window-status-format

\n\n
\n

window-status-format string
\n 设置窗口在状态行窗口列表中显示的格式。[\xe2\x80\xa6] 默认为#I:#W#F.

\n
\n\n

然后FORMATS你会学到#F“窗口标志”的意思。我没有发现任何能够直接更改与标志相关的符号的痕迹。你仍然可以使用这个:

\n\n
\n

此外,可以使用 插入 shell 命令输出的第一行#()

\n
\n\n

这意味着您可以使用trsed更改-为其他东西。您可能会对此感到震惊:

\n\n
\n

构造格式时,tmux不等待#()命令完成;相反,使用运行相同命令的先前结果,或者如果之前未运行过该命令,则使用占位符。

\n
\n\n

在我的测试中,简单的替换trsed似乎可以立即起作用,所以可能没有什么可担心的。从内部tmux运行:

\n\n
tmux set-window-option -g window-status-format "#I:#W#(printf \'%%s\\n\' \'#F\' | tr \'-\' \'<\')"\n
Run Code Online (Sandbox Code Playgroud)\n\n

或这个:

\n\n
tmux set-window-option -g window-status-format "#I:#W#(printf \'%%s\\n\' \'#F\' | sed \'s/-/</\')"\n
Run Code Online (Sandbox Code Playgroud)\n\n

我推荐tr它是因为它比 更简单、更小sed,所以它应该表现得更好(如果重要的话)。但如果您想替换-为一些多字符*字符串,那么这sed就是您的工具。例子:

\n\n
tmux set-window-option -g window-status-format "#I:#W#(printf \'%%s\\n\' \'#F\' | sed \'s/-/<--/\')"\n
Run Code Online (Sandbox Code Playgroud)\n\n

笔记:

\n\n
    \n
  • %%而不是%因为tmux解析器。
  • \n
  • tmux set-window-option window-status-format \xe2\x80\xa6(不带-g)指定单个窗口的格式;这将优先于该特定窗口的全局格式。
  • \n
  • 还有指定window-status-current-format窗口为当前窗口时使用的格式。“最后一个窗口”标志显然永远不会应用于当前窗口,但是如果您想自定义可能适用的标志,那么您需要更改window-status-current-format也需要进行更改。
  • \n
  • /etc/tmux.conf要添加到或的行~/.tmux.conf类似于:

    \n\n
    set-window-option -g window-status-format "#I:#W#(printf \'%%s\\n\' \'#F\' | tr \'-\' \'<\')"\n
    Run Code Online (Sandbox Code Playgroud)
  • \n
\n\n
\n\n

*或者更确切地说是多字节。比较一下这个

\n