Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 4 down vote accepted

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 "\033]0;$BASH_COMMAND $USER@${HOSTNAME}>$(pwd)\007"' 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 user@host>pwd.

share|improve this answer
    
And for zsh, see Title and Hardstatus in the zsh wiki. –  Gilles Apr 13 '11 at 19:28

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

$ alias foo-with-title='echo -ne "\033]0;foo\007"; foo'
share|improve this answer
    
Where is this documented? –  enzotib Mar 1 '12 at 15:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.