Bash Prompting

I pasted my bash prompt some months ago on a KDE channel on IRC. Today I got a nice e-mail, asking for it, since it was lost in a hard disk format.

This made me realize how much I like that prompt and how used to it, I am. So i decided to put it here, to have a backup. :)

\[\e[32m\][\u@\h]\[\e[0m\]\[\e[37m\][\t]\[\e[0m\]\n\[\e[34m\][\w]\[\e[0m\]>

Obviously thats very bash.

Short explanation:

\[\e[32m\]

This turns on the green pen, everything is now in green ( Numerical code: 32 )

[\u@\h]

The user (\u) and host (\h) with some eyecandy provided by @ and square brackets. This resolves on my laptop to:

[physos@davinci]

\[\e[0m\]

turning off the green pen

\[\e[37m\]

turning on the grey pen

[\t]

printing the current time in square brackets

\n

adding a newline character which does what it says

\[\e[34m\]

turning on the blue pen

[\w]

current working directory

>

and a nice little bracket to sum it up (change that to $ to be more compatible with textbooks about Linux)

When you do not get lost in square brackets and backslashs, you get something like this.

screenshot of the described bash prompt

Write a export PS1= in front of it and put it into your ~/.bashrc. Voila, bash glamour.

If you want to experiment with colors, i.e. red for root (31), I have here a list of codes.

screenshot of a colored list

This is just a short glimpse into the world of the Bash Prompt. I learned all I know from the excellent Bash Prompt HowTo in the Linux Documentation Project repository of Linux wisdom. You can find floating clocks, bold text and other miracles inside an environment variable named $PS1 there. Thanks to Giles Orr for providing this nice HowTo and the bash authors for allowing to adjust my environment to my needs, not the other way around.

  • Trackback are closed
  • Comments (5)
    • cartman
    • July 12th, 2006

    Ah rocks :)

    • nikotto
    • July 12th, 2006

    thanks, my bash prompt looks now much nicer :D

  1. bash? what\\’s that? i like zsh & RPROMPT

    Try the following in ur .zshrc

    _print_pwd () {
         wd=`pwd | sed -re \\\'s-^\\\'$HOME\\\'-~-g\\\'`
         echo -n %B
         echo -n $wd | sed -re \\\'s-/([^/])([^/]*)-/\\\\1-g\\\'
         [[ $wd == \\\'~\\\' ]] || echo -n $wd | sed -re \\\'s-.*/[^/]([^/]*$)-\\\\1-\\\'
         echo -n %b
    }
    
    setopt prompt_subst
    PROMPT=$(echo \\\'%{33[36m%}%n> %{33[0m%}\\\')
    RPROMPT=$(echo \\\'%{33[32m%}(\\\' \\\"\\\\`_print_pwd\\\\`\\\" \\\')%{33[0m%} %?\\\')
    

    :)

  2. ugh!

    i had posted plain text. some kind of formatting spoiled that post.

  3. Jep, I am running [markdown](http://daringfireball.net/projects/markdown/)

    Should be deactivated in the comments though. Have to look whats going on there.

    I am not this into zsh, since I have to work on very different systems and many different kinds of Linux and Unix installations. Bash is the common language in that case.

    zsh is a very nice Shell for administrators not alternating between UNIXes often. :)

Comment are closed.