如何自訂 tmux「最後一個視窗標記」?

如何自訂 tmux「最後一個視窗標記」?

預設情況下,Tmux 顯示-在視窗標題之後,以表示上次造訪的視窗。有沒有辦法自訂此標記並將其設定為自訂符號?謝謝,

答案1

man 1 tmux說:

預設情況下,視窗清單會按數字升序顯示目前會話中存在的視窗的索引、名稱和(如果有)標誌。它可以使用window-status-formatwindow-status-current-format選項進行自訂。此標誌是附加到視窗名稱的以下符號之一:

Symbol    Meaning
*         Denotes the current window.
-         Marks the last window (previously selected).
#         Window is monitored and activity has been detected.
!         A bell has occurred in the window.
~         The window has been silent for the monitor-silence interval.
M         The window contains the marked pane.
Z         The window's active pane is zoomed.

關於set-window-option window-status-format

window-status-format string
設定視窗在狀態列視窗清單中顯示的格式。 [...] 預設值為#I:#W#F.

然後FORMATS你會學到#F「窗口標誌」的意思。我沒有發現任何能夠直接更改與標誌相關的符號的痕跡。你仍然可以使用這個:

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

這意味著您可以使用trsed更改-為其他東西。您可能會對此感到震驚:

構造格式時,tmux不等待#()命令完成;相反,使用運行相同命令的先前結果,或者如果之前未運行過該命令,則使用佔位符。

在我的測試中,簡單的替換trsed似乎立即起作用,所以可能沒有什麼可擔心的。從內部tmux運作:

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

或這個:

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

我推薦它是tr因為它比 更簡單、更小sed,所以它應該表現得更好(如果重要的話)。但如果您想替換-為一些多字元*字串,那麼這sed就是您的工具。例子:

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

筆記:

  • %%而不是%因為tmux解析器。
  • tmux set-window-option window-status-format …(不含-g)指定單一視窗的格式;這將優先於該特定視窗的全域格式。
  • 還有window-status-current-format它指定當視窗是目前視窗時使用的格式。 「最後一個視窗」標誌顯然永遠不會應用於當前窗口,但如果您想自訂可能適用的標誌,那麼您window-status-current-format也需要進行更改。
  • /etc/tmux.conf新增到or 的行~/.tmux.conf類似於:

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

*或更確切地說是多位元組。比較

答案2

我不知道什麼時候添加的,但您可以使用 tmux 格式執行正規表示式替換,這使得實現這一點變得更簡單。從線上說明頁:

A prefix of the form ‘s/foo/bar/:’ will substitute ‘foo’ with ‘bar’ throughout.
The first argument may be an extended regular expression and a final argument may be ‘i’ to ignore case, for example:
 ‘s/a(.)/\1x/i:’ would change ‘abABab’ into ‘bxBxbx’.

因此,對於您的用例,您可以對window_flags變數內容執行替換,如下所示:

set-window-option -g window-status-format "  #{s/-/>>/:window_flags} #I #W"

相關內容