Posts Tagged ‘bash’

smiley in bash prompt

2008-02-07

After the geekdinner of last Tuesday, I couldn’t resist creating my own blog.

As an appetizer, I’ll start with some code snippets I’ve found very usefull. For example the part of my .bashrc which configures the prompt:

smiley() {
    ret_val=$?
    if [ "$ret_val" = "0" ]
    then
        echo ":)"
    else
        echo ":( ($ret_val)"
    fi
}
Green="\033[0;32m"
Yellow="\033[1;33m"
Normal="\033[0m"
PS1="\[$Yellow\]\u@\h\[$Normal\]:\[$Green\]\w \$(smiley) \[$Normal\]"

I always use this because:

  • the coloring makes it easy to see where my previous command started
  • the smiley quickly shows me if and how the previous program exited

Design a site like this with WordPress.com
Get started