好吧,既然每个人似乎都已经知道David Pashley的解决方案,那我花了很长时间才找到这个解决方案,因为它已经差不多老了,我对此感到惊讶。
该解决方案实际上负责处理bash垃圾邮件。
需要说明的是:除了研究,我在这里没有做任何其他事情。一切归功于Marius Gedminas。
这对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
这也是一个交叉发布,因为我刚刚发现了这个问题并想分享,我认为在这里也很有用。