We Recommend

bash Cookbook: Solutions and Examples for bash Users bash Cookbook: Solutions and Examples for bash Users
bash Cookbook teaches shell scripting the way Unix masters practice the craft. It presents a variety of recipes and tricks for all levels of shell programmers so that anyone can become a proficient user of the most common Unix shell -- the bash shell -- and cygwin or other popular Unix emulation packages.


Posted By

robh on 01/18/08


Tagged

Bash osx dynamic prompt


Versions (?)


Who likes this?

4 people have marked this snippet as a favorite

leachypeachy
snucko
nimoyjohnson
srinivasga


Dynamic BASH Prompt


Published in: Bash 


URL: http://blog.ubrio.us/osx/best-bash-prompt/

A very dynamic and flexible bash prompt. Personally I find this to have everything needed. It shows exit status, shortens itself for long directories, and shows bash history for easy referencing.

Hopefully it doesn't get messed up.

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

Report this snippet 

You need to login to post a comment.