The i3 FAQ has migrated to https://github.com/i3/i3/discussions. All content here is read-only.
Ask Your Question
0

How to show CLI application name in window title?

asked 2013-09-04 20:00:13 +0000

drak3 gravatar image

So, I'm curious if it is possible (and how, obviously) to show a CLI application in the terminal title bar (similar to how every non-CLI app does? I typically use gnome-terminal, which has an option to show the application where necessary, but xterm seems to exhibit the same behavior, i.e., nothing is displayed. This would be helpful when using things like htop and slurm plus a standard terminal in stacking or tabbed layout.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-09-04 22:13:14 +0000

DocOC gravatar image

You can add the following code to your .bashrc or .bashprofile (depending on whether you have your term set to open as a login shell or not.). I have it set to show the userame@host: path $ currentcommand, but you can alter the last echo -ne line to just show the command if you wish by deleting the ${USER}@${HOSTNAME}: ${PWD} \$ part, and leaving just echo -ne "\033]0;${BASH_COMMAND}\007"

case "$TERM" in
xterm*|rxvt*|screen*)
    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}: ${PWD} \$ ${BASH_COMMAND}\007"
                ;;
        esac
    }
    trap show_command_in_title_bar DEBUG
    ;;
*)
    ;;
esac
edit flag offensive delete link more

Comments

Thank you very much, kind sir!

drak3 gravatar imagedrak3 ( 2013-09-05 16:52:29 +0000 )edit

Question Tools

Stats

Asked: 2013-09-04 20:00:13 +0000

Seen: 615 times

Last updated: Sep 04 '13