PS1 heaven

Jul 31st
Posted by Michael Trausch  as GNU/Linux, UNIX, Ubuntu, computing

No, not the PlayStation. PS1, the shell prompt variable. This prompt should work on any system that has the lsb_release utility installed. If you don’t have that installed, then you can change the OS_RELEASE variable to match whatever system you’re using, by hand.

Append the following to the end of your ~/.bashrc (if you use GNU bash, anyway) and you’ll have a pretty cool looking prompt (IMHO, of course):

prompt {
    local WHITE="\[\033[1;37m\]"
    local GREEN="\[\033[0;32m\]"
    local CYAN="\[\033[0;36m\]"
    local GRAY="\[\033[0;37m\]"
    local BLUE="\[\033[0;34m\]"
    local BROWN="\[\033[0;33m\]"
    local RED="\[\033[0;31m\]"
    local RESET="\[\033[0m\]"
    local KERNEL_VERSION=`uname -r | grep -o '[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*'`
    export OS_RELEASE=`lsb_release -is`\ `lsb_release -cs | awk \
'{ print toupper(substr($0, 1, 1)) substr($0, 2) }'`

    export PS1="\n${CYAN}\D{%A, %Y-%b-%d} ${BROWN}at ${CYAN}\D{%H:%M:%S}\
 - ${RED}\u${BROWN}@${RED}\h - Linux\
 v${KERNEL_VERSION}\n${OS_RELEASE}${CYAN}:[\j]:\W> ${RESET}"
}

function pcmd {
    printf "\033]0;%s@%s - %s - %s\007" \
        "$USER" \
        "$HOSTNAME" \
        "$OS_RELEASE" \
        "${PWD/$HOME/~}"
}

prompt

case "$TERM" in
    xterm*|rxvt*)
        export PROMPT_COMMAND=pcmd
        ;;
esac
Tags

Trackbacks/Pingbacks

  1. Recent Links Tagged With "ps1" - JabberTags

Leave a Reply

Powered By Wordpress || Designed By Ridgey