Dynamic prompt line

Two lines to put on your .bashrc file to have a nice dynamic prompt line.

export MAX_PATH_LENGTH=25
export PROMPT_COMMAND='PS1="\\[\\033[32m\\][\u@\h:\`if [[ \$? = "0" ]]; then echo "\\[\\033[35m\\]"; else echo "\\[\\033[31m\\]"; fi\` \`if [[ `pwd|wc -c|tr -d " "` > $MAX_PATH_LENGTH ]]; then echo "\\W"; else echo "\\w"; fi\`\\[\\033[32m\\]]\$\[\033[0m\] "; echo -ne "\033]0;`hostname -s`:`pwd`\007"'

NB : The color of the path change if the last command written is unknown or wrong, and shortens for long directories path.

No comments: