Blog | Admin | Archives

Auto-Updating GNU Screen Window Names

It took a bunch of searching a testing, but I got something that works for me and I like well. Instead of every screen window being called “bash” or being named manually, I now have them all named after the working directory. This is the magic:

PROMPT_COMMAND='echo -ne "\033k$(basename $PWD)\033\\"'

PROMPT_COMMAND gets run every time bash displays a prompt, and those particular escape characters do the magic.

To avoid crap outside of screen, I did this:

case ${TERM} in
screen)
export PROMPT_COMMAND='echo -ne "\033k$(basename $PWD)\033\\"'
;;
esac

Which is more general than it needs to be, but maybe I’ll expand it in the future.

Leave a Reply