Differences between revisions 9 and 12 (spanning 3 versions)
Revision 9 as of 2011-04-03 15:10:11
Size: 942
Editor: adsl-75-61-109-235
Comment: Reverting my change since there's more than one occurrence of '\e'. Instead, added note at bottom about substituting '\x1b'.
Revision 12 as of 2016-10-22 16:49:46
Size: 938
Editor: politkovskaja
Comment: remove space to the right of >
Deletions are marked like this. Additions are marked like this.
Line 12: Line 12:
trap 'printf "\e]2;%s\a" "$(HISTTIMEFORMAT='' history 1)" > /dev/tty' DEBUG trap 'printf "\e]2;%s\a" "$(HISTTIMEFORMAT= history 1)" >/dev/tty' DEBUG
Line 20: Line 20:
trap 'printf "\e]2;%s\a" "$BASH_COMMAND" > /dev/tty' DEBUG trap 'printf "\e]2;%s\a" "$BASH_COMMAND" >/dev/tty' DEBUG
Line 23: Line 23:
For Posix-compliant shells which don't recognize '\e' as a character sequence to be interpreted as `Escape`, '\x1b' may be substituted instead. For Posix-compliant shells which don't recognize '\e' as a character sequence to be interpreted as `Escape`, '\033' may be substituted instead.

How can I set the contents of my terminal's title bar?

If you have a terminal that understands xterm-compatible escape sequences, and you just want to set the title one time, you can use a function like this:

settitle() { printf '\e]2;%s\a' "$*"; }

If you want to set the title bar to the currently-running command line every time you type a command, then this solution approximates it:

trap 'printf "\e]2;%s\a" "$(HISTTIMEFORMAT= history 1)" >/dev/tty' DEBUG

However, it leaves the command history number in place, and it doesn't trigger on explicit subshells like (cd foo && make).

Or to use just the name and arguments of the current simple command:

trap 'printf "\e]2;%s\a" "$BASH_COMMAND" >/dev/tty' DEBUG

For Posix-compliant shells which don't recognize '\e' as a character sequence to be interpreted as Escape, '\033' may be substituted instead.

BashFAQ/093 (last edited 2016-10-22 16:49:46 by politkovskaja)