PROMPT_COMMAND hook configuration¶
PROMPT_COMMAND is a Bash environment variable used to execute a command or a series of commands before the display of each primary prompt.^[400-devops-02-os-and-linux-basics-windows.md]
Syntax¶
The content of PROMPT_COMMAND is typically executed as a standard Bash command.^[400-devops-02-os-and-linux-basics-windows.md] When appending to an existing configuration, it is common practice to include the previous value of PROMPT_COMMAND to avoid overwriting it^[400-devops-02-os-and-linux-basics-windows.md]. This is achieved using parameter expansion to conditionally prepend the existing command string followed by a separator.
Usage Example¶
A common application of this hook is to integrate Windows Terminal features within a Bash environment, such as Git Bash. By configuring the hook, one can broadcast the current working directory path to the terminal emulator^[400-devops-02-os-and-linux-basics-windows.md].
The following configuration example appends a printf command to the existing hook to format the current working directory ($PWD) into a Windows path (wslpath -w) and emit it via an escape sequence^[400-devops-02-os-and-linux-basics-windows.md]:
PROMPT_COMMAND=${PROMPT_COMMAND:+"$PROMPT_COMMAND; "}'printf "\e]9;9;%s\e\\" "$(wslpath -w "$PWD")"'
Related Concepts¶
- [[Bash Configuration]]
- [[Windows Terminal]]
Sources¶
^[400-devops-02-os-and-linux-basics-windows.md]