-
#!/bin/bash
-
-
# termwide prompt
-
# by Giles - created 2 November 98
-
# adapted by Michiel Roos somewhere in 2007
-
#
-
# The idea here is to have the upper line of this two line prompt
-
# always be the width of your term. Do this by calculating the
-
# width of the text elements, and putting in fill as appropriate
-
# or left-truncating $PWD.
-
#
-
-
function prompt_command {
-
# Calculate the width of the prompt:
-
hostnam=$(echo -n $HOSTNAME | sed -e "s/[\.].*//")
-
# "whoami" and "pwd" include a trailing newline
-
usernam=$(whoami)
-
let usersize=$(echo -n $usernam | wc -c | tr -d " ")
-
newPWD="${PWD}"
-
let pwdsize=$(echo -n ${newPWD} | wc -c | tr -d " ")
-
-
# load monitor
-
load1=$(uptime | sed -e "s/.*average: \([^ ]*\), .*$/\1/")
-
load5=$(uptime | sed -e "s/.*average: [^ ]* \([^ ]*\), .*$/\1/")
-
load15=$(uptime | sed -e "s/.*average: [^ ]* [^ ]* \([^ ]*\)$/\1/")
-
-
# Add all the accessories below ...
-
let promptsize=$(echo -n ".-(${usernam}@${hostnam}:${load1} ${load5} ${load15})---(${PWD}]" | wc -c | tr -d " ")
-
let fillsize=${COLUMNS}-${promptsize}
-
fill=""
-
while [ "$fillsize" -gt "0" ]
-
do
-
fill="${fill}-"
-
let fillsize=${fillsize}-1
-
done
-
-
if [ "$fillsize" -lt "0" ]
-
then
-
let cut=3-${fillsize}
-
newPWD="...$(echo -n $PWD | sed -e "s/\(^.\{$cut\}\)\(.*\)/\2/")"
-
fi
-
}
-
-
PROMPT_COMMAND=prompt_command
-
-
function termwide {
-
case $TERM in
-
xterm*)
-
TITLEBAR='\[\033]0;\u@\h:\w\007\]'
-
;;
-
*)
-
TITLEBAR=""
-
;;
-
esac
-
-
local RED="\[\033[0;31m\]"
-
local GREEN="\[\033[0;32m\]"
-
local YELLOW="\[\033[0;33m\]"
-
local BLUE="\[\033[0;34m\]"
-
local MAGENTA="\[\033[0;35m\]"
-
local CYAN="\[\033[0;36m\]"
-
local WHITE="\[\033[0;37m\]"
-
local NO_COLOUR="\[\033[0m\]"
-
-
local FILL=$WHITE
-
local BRACKETS=$RED
-
local USER=$CYAN
-
local AT=$WHITE
-
local HOST=$GREEN
-
local PWDIR=$CYAN
-
local LOAD1=$RED
-
local LOAD5=$YELLOW
-
local LOAD15=$GREEN
-
-
PS1="$TITLEBAR\
-
$FILL.$BRACKETS-(\
-
$USER\${usernam}$AT@$HOST\${hostnam}\
-
$AT:$LOAD1\${load1} $LOAD5\${load5} $LOAD15\${load15}$BRACKETS)-$FILL-\${fill}$BRACKETS-[\
-
$PWDIR\${newPWD}\
-
$BRACKETS]\
-
\n\
-
$FILL\$(cat ~/.bash_backtick)-\
-
$BRACKETS_$FILL\$$NO_COLOUR "
-
-
PS2="$BRACKETS-$FILL-$FILL-$NO_COLOUR "
-
}




Good Job Michiel! :)