Skip to content

Instantly share code, notes, and snippets.

@borodiychuk
Created December 20, 2012 21:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save borodiychuk/4348835 to your computer and use it in GitHub Desktop.
Save borodiychuk/4348835 to your computer and use it in GitHub Desktop.
Pretty and colored bash prompt.
export PROMPT_COMMAND='PS1="\[\033[0;33m\]\!\[\033[1;30m\]|\[\033[1;34m\]\$(date +%H:%M)\[\033[1;30m\]|\`if [[ $? = "0" ]]; then echo "\\[\\033[32m\\]"; else echo "\\[\\033[31m\\]"; fi\`\u.\h\[\033[1;30m\]:\[\033[1;37m\]\`if [[ `pwd|wc -c|tr -d " "` > 18 ]]; then echo "\\W"; else echo "\\w"; fi\` \`if [[ "`id -u`" = "0" ]]; then echo "\\[\\033[31m\\]"; else echo "\\[\\033[32m\\]"; fi\`\\$\[\033[0;0m\] "; echo -ne "\033]0;`hostname -s`:`pwd`\007"'
@borodiychuk
Copy link
Author

It looks like number|hh:mm|user.host:folder $ for regular user and number|hh:mm|user.host:folder # for root.

To use it add the gist content to the end of /etc/bash.bashrc (to use system-wide) or ~/.bashrc (restrict only for specific user).

@borodiychuk
Copy link
Author

The screenshot is here: http://noty.net/posts/708

@artvolk
Copy link

artvolk commented Dec 24, 2012

What is number (first part)?

@artvolk
Copy link

artvolk commented Dec 24, 2012

And yes, maybe SVN revision \ git branch? :)

@borodiychuk
Copy link
Author

@artvolk, this is the command number in the bash history. So later you can run the command from histoy by typing !123 in the shell prompt.

@artvolk
Copy link

artvolk commented Dec 26, 2012

Thanks, already put in in all my .bashrc files :)

@dva
Copy link

dva commented Dec 26, 2012

Very very.
Thanks :)

@artvolk
Copy link

artvolk commented Jan 22, 2013

It seems it breaks in Ubuntu local console (over SSH it works).

@borodiychuk
Copy link
Author

@artvolk: how comes that? I use it always on my local ubuntu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment