Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 14 Jul 2003 10:24:21 -0700
From:      Joshua Oremzn <oremanj@webserver.get-linux.org>
To:        Kevin Berrien <kblists@comcast.net>
Cc:        questions@freebsd.org
Subject:   Color shell prompts (was Re: FreeBSD 4.8-RELEASE mutt & color (color))
Message-ID:  <20030714172421.GC11619@webserver.get-linux.org>
In-Reply-To: <3F12DF9F.2060304@comcast.net>
References:  <20030714013931.7485.qmail@web41107.mail.yahoo.com> <3F12DF9F.2060304@comcast.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Jul 14, 2003 at 12:51:43PM -0400 or thereabouts, Kevin Berrien wrote:
> Speaking of color.  Does anyone have a good tutorial/script to add color 
> in bash as one finds in the newer linux distributions?
> 

"The Bash-Prompt HOWTO" @ tldp.org
is a good one. Just to give you an idea about how crazy this all can
get, take a look at this prompt (for zsh). Note that ^[ means the
real ESC character, not caret + left bracket. Sorry about the long lines:

PS1='%{^[[1;34m%}--[ %{^[[1;36m%}$(pwd), $(ls -1 | wc -l | tr -d " ") files / ${SIZE}%{^[[1;34m%} ]-- --[ %{^[[1;36m%}$(date "+%I:%M %p")%{^[[1;34m%} ]-- --[ %{^[[1;36m%}%n @ %M[$(jobs | wc -l | tr -d " ")] / $(tty | sed "s:/dev/pts/:ttyp:g;s:/dev/::g")%{^[[1;34m%} ]--
--[ %{^[[1;36m%}$(ps ax | wc -l | tr -d " ") processes%{^[[1;34m%} ]-- --[ %{^[[1;36m%}$(who | wc -l | tr -d " ") users%{^[[1;34m%} ]--
--[ %{^[[1;36m%}%# %{^[[1;34m%}]-- %{^[[0m%}'
PS2='%{^[[1;34m%}--[ %{^[[1;36m%}%_ > %{^[[1;34m%}]-- %{^[[0m%}'

function precmd () {
    let TotalBytes=0

    for Bytes in $(command ls -l | grep "^-" | awk '{ print $5 }')
    do
        let TotalBytes=$TotalBytes+$Bytes
    done

    if [ $TotalBytes -lt 1024 ]; then
        TotalSize=$(echo -e "scale=0 \n$TotalBytes \nquit" | bc | tr -d '\n')
        suffix=" bytes"
    elif [ $TotalBytes -lt 1048576 ]; then
        TotalSize=$(echo -e "scale=0 \n$TotalBytes/1024 \nquit" | bc | tr -d '\n')
        suffix="K"
    elif [ $TotalBytes -lt 1073741824 ]; then
        TotalSize=$(echo -e "scale=0 \n$TotalBytes/1048576 \nquit" | bc | tr -d '\n')
        suffix="M"
    else
        TotalSize=$(echo -e "scale=0 \n$TotalBytes/1073741824 \nquit" | bc | tr -d '\n')
        suffix="G"
    fi

    SIZE="${TotalSize}${suffix}"

    UPTIME="`uptime | sed -e 's/.* \(.* days,\)\? \(.*:..,\) .*/\1 \2/' \
                          -e 's/,//g' -e 's/ up //'`"
}

It makes a prompt like this, but in color:
--[ /, 33 files / 10M ]-- --[ 10:23 AM ]-- --[ oremanj @ webserver.get-linux.org[0] / ttyv1 ]--
--[ 136 processes ]-- --[ 4 users ]--
--[ % ]-- <command-goes-here>

-- Josh

P.S. Of course I don't use that prompt!

> 
> _______________________________________________
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030714172421.GC11619>