我如何重命名一个窗格在tmux?
当前回答
对我来说,最简单的选择是重命名终端的标题。 请参阅:https://superuser.com/questions/362227/how-to-change-the-title-of-the-mintty-window
在这个答案中,他们提到要修改PS1变量。注:我的情况是cygwin特有的。
博士TL; 把这个放在你的。bashrc文件中:
function settitle() {
export PS1="\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n$ "
echo -ne "\e]0;$1\a"
}
把它放在你的.tmux.conf文件中,或者类似的格式:
set -g pane-border-status bottom
set -g pane-border-format "#P #T #{pane_current_command}"
然后你可以在控制台中输入以下内容来更改窗格的标题:
settitle titlename
其他回答
对我来说,最简单的选择是重命名终端的标题。 请参阅:https://superuser.com/questions/362227/how-to-change-the-title-of-the-mintty-window
在这个答案中,他们提到要修改PS1变量。注:我的情况是cygwin特有的。
博士TL; 把这个放在你的。bashrc文件中:
function settitle() {
export PS1="\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n$ "
echo -ne "\e]0;$1\a"
}
把它放在你的.tmux.conf文件中,或者类似的格式:
set -g pane-border-status bottom
set -g pane-border-format "#P #T #{pane_current_command}"
然后你可以在控制台中输入以下内容来更改窗格的标题:
settitle titlename
是的,您可以重命名窗格名称,而不仅仅是以tmux >= 2.3开头的窗口名称。只需在shell中输入以下内容:
printf '\033]2;%s\033\\' 'title goes here'
你可能需要在.tmux.conf中添加以下内容来显示窗格名称:
# Enable names for panes
set -g pane-border-status top
你也可以自动分配一个名称:
set -g pane-border-format "#P: #{pane_current_command}"
要重命名窗格,在tmux命令提示符中写入以下命令:
select-pane -T 'NEW PANE NAME'
要将它绑定到一个键(例如:u),在~/.tmux.conf文件中写入以下代码:
bind u command-prompt "select-pane -T '%%'"
然后您可以通过<prefix>u重命名该窗格
FYI:
要打开命令提示符,您需要<prefix>: <prefix>默认为C-b(可以通过set -g prefix NEW_KEY更改)
同样,在编写脚本时,您可以在创建窗口时指定一个名称-n <窗口名称>。例如:
# variable to store the session name
SESSION="my_session"
# set up session
tmux -2 new-session -d -s $SESSION
# create window; split into panes
tmux new-window -t $SESSION:0 -n 'My Window with a Name'
你可以通过在tmux.conf中设置窗格边框来调整窗格标题,例如:
###############
# pane border #
###############
set -g pane-border-status bottom
#colors for pane borders
setw -g pane-border-style fg=green,bg=black
setw -g pane-active-border-style fg=colour118,bg=black
setw -g automatic-rename off
setw -g pane-border-format ' #{pane_index} #{pane_title} : #{pane_current_path} '
# active pane normal, other shaded out
setw -g window-style fg=colour28,bg=colour16
setw -g window-active-style fg=colour46,bg=colour16
其中pane_index, pane_title和pane_current_path是由tmux自身提供的变量。
在重新加载配置或启动一个新的tmux会话后,您可以像这样设置当前窗格的标题:
tmux select-pane -T "fancy pane title";
#or
tmux select-pane -t paneIndexInteger -T "fancy pane title";
如果所有窗格都有一些进程在运行,所以你不能使用命令行,你也可以在按下前缀bind(默认为C-b)和冒号(:)后输入命令,而不需要在命令前面有“tmux”:
select-pane -T "fancy pane title"
#or:
select-pane -t paneIndexInteger -T "fancy pane title"