planetp
planetp

Reputation: 16065

What does this PROMPT_COMMAND do?

I have this in /etc/bash.bashrc on my Linux system:

PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND; }'printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"'

From man bash I understand that it sets a command to be executed prior to issuing each prompt, but I'm wondering what exactly it's doing.

Upvotes: 5

Views: 1997

Answers (2)

Eugene Yarmash
Eugene Yarmash

Reputation: 149736

Basically, it updates the title of the terminal after every command you issue to reflect the current values of the envariables, using XTerm escape sequences.

Some of the escape sequences recognized by XTerm-compatible terminal emulators:

ESC]0;stringBEL — Set icon name and window title to string
ESC]1;stringBEL — Set icon name to string
ESC]2;stringBEL — Set window title to string

where ESC is the escape character (\033), and BEL is the bell character (\007).

Upvotes: 4

David Hoelzer
David Hoelzer

Reputation: 16331

Sets your prompt to be whatever is being executed now in addition to a printf that will show your username @ your hostname with your present working directory. You'll have to look up the \033]0; terminal code yourself.

Upvotes: 1

Related Questions