change terminal title

I want to make a shell alias that starts a certain program and also changes the title of the terminal to the name of the program. How can I do that?

In case it matters, I am running the terminal on Ubuntu and connecting to a Debian server via ssh.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

In Bash, I use the following trap command in the last line of my .bashrc to echo all commands to the titlebar.

# trap commands and echo them to xterm titlebar. Must be last line.
trap 'echo -ne "33]0;$BASH_COMMAND <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="04205157415644">[email protected]</a>${HOSTNAME}>$(pwd)07"' DEBUG

So if you execute sleep 10, you will see your titlebar change to sleep 10 for the duration of the command, after which it will change back to [email protected]>pwd.

Method 2

Most terminals recognize a certain escape sequence as an attempt to change the title, so this will work:

$ alias foo-with-title='echo -ne "33]0;foo07"; foo'


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x