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?
Prompt Madness!
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"'
The second half (from “echo -ne…” on) is for the Terminal’s title.
Comments
Trackbacks
- Blog.ubrious » Blog Archive » OSX Terminal Niceties for Remote Servers
- Pronto! Prompt me, Bash! « sysblogd
- being (no)body » m3talink for April 9th







Robbie March 3rd
very cool
, i would like to change it a bit though and swop it around so that the command numbers get changed [001]=green for good , [002]red for bad. do you know how i could do that? i still like my prompt as” [user@comp] ~ $ ” although i’ve now added ” [829][user@comp] ~ $ ” nice work though
I’ve been inspired
Jadu Saikia December 28th
cool play with PS1, nice info, good tip. Thanks.
// jadu
Talon June 23rd
That person above is a complete newb if he doesnt realise that files chmoded to 0000 show as white. !
:/ :/
Add Yours
YOU