use*_*735 3 gnome-terminal terminal-emulator
如何将当前正在运行的进程名称放入 GNOME 终端选项卡标题(或只有一个选项卡时的标题栏)?
尽管https://superuser.com/questions/42362/gnome-terminal-process-name-in-tab-title提供了一个解决方案(见下文),但它在启动时将每个选项卡都塞满了垃圾,以致于看起来已损坏。有没有更好的办法?
case "$TERM" in
xterm*|rxvt*)
set -o functrace
trap 'echo -ne "\e]0;$BASH_COMMAND\007"' DEBUG
PS1="\e]0;\s\007$PS1"
;;
*)
;;
esac
Run Code Online (Sandbox Code Playgroud)
小智 5
好吧,既然每个人似乎都知道 David Pashley 的解决方案,我有点惊讶我花了这么长时间才找到这个解决方案。它实际上处理了 bash 完成问题。
需要明确的是:我在这里除了研究什么也没做。所有功劳都归功于 Marius Gedminas ( http://mg.pov.lt/blog/bash-prompt.html )。
这对我来说非常适合 Gnome-Terminal/Terminator
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
# Show the currently running command in the terminal title:
# http://www.davidpashley.com/articles/xterm-titles-with-bash.html
show_command_in_title_bar()
{
case "$BASH_COMMAND" in
*\033]0*)
# The command is trying to set the title bar as well;
# this is most likely the execution of $PROMPT_COMMAND.
# In any case nested escapes confuse the terminal, so don't
# output them.
;;
*)
echo -ne "\033]0;${USER}@${HOSTNAME}: ${BASH_COMMAND}\007"
;;
esac
}
trap show_command_in_title_bar DEBUG
;;
*)
;;
esac
Run Code Online (Sandbox Code Playgroud)