Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 677
user490735 Avatar asked Oct 17 '25 02:10

user490735


1 Answers

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:
    # https://www.davidpashley.com/articles/xterm-titles-with-bash/
    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

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!