4

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.

6

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.

7

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'
  • 1
    Where is this documented? – enzotib Mar 1 '12 at 15:00
  • This works in a bare shell. Using tmux/byobu this doesn't seem to work. I also tried bash -c 'echo -ne "\033]0;foo\007"' – oneindelijk Jul 3 at 7:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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