How to view process name in terminal-emulator tab or title bar

3k Views Asked by At

How can I put the current running process name into a GNOME Terminal tab title (or title bar when there's only one tab)?

Although https://superuser.com/questions/42362/gnome-terminal-process-name-in-tab-title provides a solution (below), it completely clutters each tab with garbage when it starts so as to appear broken. Is there a better way?

case "$TERM" in
xterm*|rxvt*)
    set -o functrace
    trap 'echo -ne "\e]0;$BASH_COMMAND\007"' DEBUG
    PS1="\e]0;\s\007$PS1"
    ;;
*)
    ;;
esac
1

There are 1 best solutions below

0
AudioBubble On

Well, since everyone already seems to know David Pashley's solution I'm kind of surprised it took me so long to find this one. It actually takes care of the bash-completion problem.

To be clear: I did nothing on my own here but research. All credit goes to Marius Gedminas (http://mg.pov.lt/blog/bash-prompt.html).

This works perfectly for me with 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