My Root Prompt

This is a prompt I used for a long time in my root account. It's derived from power prompt 2, which was far too big and slow. This is somewhat better, and I've added left-truncation to the $PWD, so it doesn't grow to large.

Code:


#!/bin/bash

# $Author: giles $, $Date: 1999/07/29 17:59:59 $
# $Source: /home/giles/.bashprompt/bashthemes/RCS/rprom,v $
# $Revision: 1.3 $
#
# $Log: rprom,v $
# Revision 1.3  1999/07/29 17:59:59  giles
# Terminated colours correctly at prompt end.
#
# Revision 1.2  1999/06/06 18:13:30  giles
# Made the length of the kept part of the PWD flexible - a variable
# named near the beginning of the script.
#
# Revision 1.1  1999/06/06 18:02:35  giles
# Initial revision
#

function prompt_command {
#   How many characters of the $PWD should be kept
local pwd_length=30
#   Create TotalMeg variable: sum of visible file sizes in current directory
local TotalBytes=0
for Bytes in $(ls -l | grep "^-" | cut -c30-41)
do
    let TotalBytes=$TotalBytes+$Bytes
done
TotalMeg=$(echo -e "scale=3 \nx=$TotalBytes/1048576\n if (x<1) {print \"0\"} \n 
print x \nquit" | bc)

#   Count visible files:
let files=$(ls -l | grep "^-" | wc -l | tr -d " ")
let hiddenfiles=$(ls -l -d .* | grep "^-" | wc -l | tr -d " ")
let executables=$(ls -l | grep ^-..x | wc -l | tr -d " ")
let directories=$(ls -l | grep "^d" | wc -l | tr -d " ")
let hiddendirectories=$(ls -l -d .* | grep "^d" | wc -l | tr -d " ")-2

if [ $(echo -n $PWD | wc -c | tr -d " ") -gt $pwd_length ]
then
   newPWD="...$(echo -n $PWD | sed -e "s/.*\(.\{$pwd_length\}\)/\1/")"
else
   newPWD="$(echo -n $PWD)"
fi
}

PROMPT_COMMAND=prompt_command

function rprom {

local        BLUE="\[\033[0;34m\]"
local  LIGHT_GRAY="\[\033[0;37m\]"
local LIGHT_GREEN="\[\033[1;32m\]"
local  LIGHT_BLUE="\[\033[1;34m\]"
local  LIGHT_CYAN="\[\033[1;36m\]"
local      YELLOW="\[\033[1;33m\]"
local       WHITE="\[\033[1;37m\]"
local         RED="\[\033[0;31m\]"
local   NO_COLOUR="\[\033[0m\]"

case $TERM in
    xterm*)
        TITLEBAR='\[\033]0;\u@\h:\w\007\]'
        ;;
    *)
        TITLEBAR=""
        ;;
esac

PS1="$TITLEBAR\
$BLUE[$RED\$(date +%H%M)$BLUE]\
$BLUE[$RED\u@\h$BLUE]\
$BLUE[\
$LIGHT_GRAY\${files}.\${hiddenfiles}-\
$LIGHT_GREEN\${executables}x \
$LIGHT_GRAY(\${TotalMeg}Mb) \
$LIGHT_BLUE\${directories}.\
\${hiddendirectories}d\
$BLUE]\
\n\
$BLUE[$RED\$newPWD$BLUE]\
$WHITE\$\
\
$NO_COLOUR "
PS2='> '
PS4='+ '
}


http://gilesorr.com/bashprompt/prompts/rprom.html (2.7Kb)
Last modified 20060518 by giles