I want to set the Xterm window title to switch between two states:
- When a command is running, show the command name (e.g. "less")
- When no command is running, show the current path (e.g. "src")
I can create an Xterm window title with the current path with:
$ export PROMPT_COMMAND='echo -ne "\033]0;`basename ${PWD}`\007"'
And I can show the current running command by adding a trap
statement to .bashrc
:
$ trap 'echo -ne "\033]0;$BASH_COMMAND\007"' DEBUG
But I'm not able to automatically switch between the two. Is it possible?
EDIT: @terdon shows a solution that works in a regular xterm, that's cool! But I failed to mention that I use the MacOSX Terminal.app. That shows still shows "bash" instead of the current path when no command is running. With a little tinkering I figured out how to solve this.
PROMPT_COMMAND
displays the current directory when no command runs and the accepted answer of the linked question displays the current command while one is running. – manatwork Sep 20 '13 at 09:39trap
example in .bashrc, I always have the current command in the title (includingbash
if no command is running). If I usePROMPT_COMMAND
, I always have the path. I only want to display the current path if no command is running. – neu242 Sep 20 '13 at 10:06