将 tmux 标题设置为路径

将 tmux 标题设置为路径

我目前正在设置 tmux 以通过执行以下操作将窗口标题更新为当前正在运行的命令的名称:

set-option -g set-titles on
set-option -g set-titles-string '#S:#I.#P #W' # window number,program name,active (or not)
set-window-option -g automatic-rename on      # auto name

但是,当没有执行任何命令时,它只显示“N:zsh”(其中 N 是窗口号)。

当没有执行任何命令时,有没有办法在窗口标题中显示路径的当前最后一个元素?因此,如果当前路径是 /usr/src/linux,则窗口标题应该是“N:linux”。

谢谢

答案1

我有一个半解决方案来展示两者:

# window titles
set-window-option -g window-status-current-format ' #[fg=white]** #[fg=white,bold][#{window_index}] #[fg=green]#{pane_current_command} #[fg=cyan]#(pwd="#{pane_current_path}"; echo ${pwd####*/}) #[fg=white]**'
set-window-option -g window-status-format '#[fg=colour244,bold][#{window_index}] #[fg=colour244]#{pane_current_command} #[fg=colour244]#(pwd="#{pane_current_path}"; echo ${pwd####*/})'

将这些行添加到您的~/.tmux.conf并将获得:

在此处输入图片描述

相关内容