I want my gnome-terminal to show my current user and host in its titlebar, and that of the remote when I am using ssh.

To do that, I created a script ~/bin/ssh, with ~/bin in my PATH before /usr/bin:

echo -ne "\033]0;${1}\007"
/usr/bin/ssh $@

This works fine (arguably, not robust for unexpected argument order). Even after exiting the ssh session, the window title recovers nicely.

My problem is that other programs that try to use ssh are disturbed by the stdout this generates. git fetch for example, barfs on \033]0;.

My question is: how can I better the script so that it keeps its name ssh, but gives stdout only in relevant cases?

There must be some kind of variable to tell if there is any window title to change? I guess TERM is still defined when running via git, so that wouldn't work.

Can I send the string to another stream?

Should I parse the ssh options and not output to stdout in certain conditions?


You want your script to check if its stdout is going to a tty or not.

Referring to this stackoverflow question, check isatty in bash


# set the terminal title, if I'm running in a terminal
if [[ -t 1 ]]; then echo -ne "\033]0;${1}\007"; fi

/usr/bin/ssh "$@"

Note that you always want to quote "$@"

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.