Tuesday, January 27, 2015

Dynamic shell prompt

Dynamic shell prompt can change it's form according to some events going on on terminal. It can change e.g. color, if the previous command execution was unsuccessful, or it can display various information.
In this post, there is an example of such a prompt. It displays information, when you enter specified working directory.

The picture below shows my configuration:

This is achieved with setting a variable PROMPT_COMMAND which is evaluated every time you run a command. In my case, there is a condition, which looks for matching path.



# dynamic PS prompt
export PROMPT_COMMAND='PS1="$(if [ "$(pwd | grep /mnt/storage/backup_git)" ]; then echo "\\[\\033[32m\\]backup_git "; fi;)\[\033[01;31m\]\h\[\033[01;34m\] \W \$\[\033[00m\] "'


No comments:

Post a Comment