<HTML ><HEAD ><TITLE >A "Power User" Prompt</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Bash Prompt HOWTO" HREF="index.html"><LINK REL="UP" TITLE="Example Prompts" HREF="c816.html"><LINK REL="PREVIOUS" TITLE="Elite from Bashprompt Themes" HREF="x847.html"><LINK REL="NEXT" TITLE="Prompt Depending on Connection Type" HREF="x865.html"></HEAD ><BODY CLASS="SECT1" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Bash Prompt HOWTO: </TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="x847.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Chapter 12. Example Prompts</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="x865.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="SECT1" ><H1 CLASS="SECT1" ><A NAME="AEN860" ></A >12.5. A "Power User" Prompt</H1 ><P >I actually did use this prompt for a while, but it results in noticeable delays in the appearance of the prompt on a single-user PII-400, so I wouldn't recommend using it on a multi-user P-100 or anything ... A rewrite using newer Bash functionality might help, but look at it for ideas rather than as a practical prompt. </P ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><FONT COLOR="#000000" ><PRE CLASS="PROGRAMLISTING" > #!/bin/bash #---------------------------------------------------------------------- # POWER USER PROMPT "pprom2" #---------------------------------------------------------------------- # # Created August 98, Last Modified 9 November 98 by Giles # # Problem: when load is going down, it says "1.35down-.08", get rid # of the negative function prompt_command { # Create TotalMeg variable: sum of visible file sizes in current directory local TotalBytes=0 for Bytes in $(ls -l | grep "^-" | awk '{print $5}') 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) # 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. # local one=$(uptime | sed -e "s/.*load average: \(.*\...\), \(.*\...\), \(.*\...\)/\1/" -e "s/ //g") local five=$(uptime | sed -e "s/.*load average: \(.*\...\), \(.*\...\), \(.*\...\).*/\2/" -e "s/ //g") local diff1_5=$(echo -e "scale = scale ($one) \nx=$one - $five\n if (x>0) {print \"up\"} else {print \"down\"}\n print x \nquit \n" | bc) loaddiff="$(echo -n "${one}${diff1_5}")" # 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" ] then links="" else links=" ${linktemp}l" fi unset linktemp let devicetemp=$(ls -l | grep "^[bc]" | wc -l | tr -d " ") if [ "$devicetemp" -eq "0" ] then devices="" else devices=" ${devicetemp}bc" fi unset devicetemp } PROMPT_COMMAND=prompt_command 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\]" 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\ $LIGHT_CYAN\${links}\ $YELLOW\${devices}\ $BLUE]\ $BLUE[${WHITE}\${loaddiff}$BLUE]\ $BLUE[\ $WHITE\$(ps ax | wc -l | sed -e \"s: ::g\")proc\ $BLUE]\ \n\ $BLUE[$RED\$PWD$BLUE]\ $WHITE\$\ \ $NO_COLOUR " PS2='> ' PS4='+ ' } </PRE ></FONT ></TD ></TR ></TABLE ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="x847.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="x865.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Elite from Bashprompt Themes</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="c816.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Prompt Depending on Connection Type</TD ></TR ></TABLE ></DIV ></BODY ></HTML >