Best Bash Prompt
Okay — so after that last post I decided it was time for a change. I’ve had the same bash prompt for years and was starting to get tired of it. Over the past 30 or so minutes I’ve been
hating life learning way more than I wanted to about PS1, colors and embedded IF statements.
And yes, this needs it own post simply for the fact that this is an insane prompt. Heres what it is/can do:
- Automatically shortens itself if the path is longer than 18 charachters
This is what I’ve always wanted since I usually name my folders after the website URL — and I HATE 2 line prompts.
- Changes to red if the last command didn’t have a return code of 0
- Includes your bash history # for easy history command repeating
- Is pretty neat and trim
Why is this rad?
I’ll let this image explain what it does and how it looks…
I’m tossing up a text file here -> best_bash_prompt_ever.txt — since the escaping will probably be messed up.
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 " "` > 18 ]]; then echo "\\W"; else echo "\\w"; fi\`]\$\[\033[0m\] "; echo -ne "\033]0;`hostname -s`:`pwd`\007"'
- Blog.ubrious » Blog Archive » OSX Terminal Niceties for Remote Servers
- Pronto! Prompt me, Bash! « sysblogd
- being (no)body » m3talink for April 9th