11.5. A "Power User" Prompt

I actually did use this prompt for a while, but it resulted in noticeable delays in the appearance of the prompt on a single-user PII-400. On modern (2007) machines you're unlikely to notice this, but look at it for ideas rather than as a practical prompt. Requires the lsbytesum script.

#       POWER USER PROMPT "pprom2"
#   copyright 2007 Giles Orr
#   Placed under the Gnu Public License v.3

function prompt_command
#      This is used to calculate the differential in load values
#      provided by the "uptime" command.  "uptime" gives load 
#      averages at 1, 5, and 15 minute marks.  The HERE document
#      is needed because "read" won't take data from subprocesses
#      in a pipe.  "fifteen" is unused but available.
local one
local five
read one five fifteen << HERE
  $(uptime | sed -e "s/.*load average: \(.*\...\), \(.*\...\), \(.*\...\)/\1 \2 \3/")
loaddiff=$(echo -e "scale = scale ($one) \nx=$one - $five\n {print $one} \n if (x>0) {print \"^\", x} else {print \"v\", -x}\nquit \n" | 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
let linktemp=$(ls -l | grep "^l" | wc -l | tr -d " ")
if [ "$linktemp" -eq "0" ]
    links=" ${linktemp}l"
unset linktemp
let devicetemp=$(ls -l | grep "^[bc]" | wc -l | tr -d " ")
if [ "$devicetemp" -eq "0" ]
    devices=" ${devicetemp}bc"
unset devicetemp



function pprom2 {

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\]"

case $TERM in

$LIGHT_GREEN\${executables}x \
$LIGHT_GRAY(\$(lsbytesum)) \
$WHITE\$(ps ax | wc -l | sed -e \"s: ::g\")p\
PS2='> '
PS4='+ '

The information provided is extremely terse, but can be very useful particularly if you're doing file and directory housekeeping. You're shown the number of normal files followed by a "." and the number of dot files, in gray. Then the number of those files that are executable followed by the letter "x", in green (I used the default colours for "ls" output). Then the size of all the visible files (this could be changed in the "lsbytesum" script to include all files). Next are the number of normal directories, a ".", and the number of dot directories followed by the letter "l", in blue. If there are links, they will appear next with the letter "l", in cyan. And last, if there are devices, the count shows up followed by a "bc", in yellow. The next box contains the one minute load with a "^" indicating it's up or a "v" indicating it's down relative to the five minute load, and the difference between them. The next box contains the number of running processes on the machine. The last box on the first line contains the current working directory. The two boxes on the second line of the prompt are more "traditional," including a 24 hour clock and "user@hostname".