Differences between revisions 5 and 7 (spanning 2 versions)
Revision 5 as of 2009-07-15 18:37:02
Size: 52
Editor: GreyCat
Comment: This one has been merged into 044 and is now available.
Revision 7 as of 2009-09-11 16:46:15
Size: 795
Editor: NeilMoore
Comment: fix up debug trap, add another version with $BASH_COMMAND
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:
== Placeholder ==
Placeholder.
== 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
}}}

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

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