twtty Prompt
I initially wrote a prompt called "termwide" in response to Dan's complaint that having the $PWD in the prompt causes the prompt size to change drastically. "Termwide" is a two line prompt that stays the width of your term at all times, and puts the $PWD on the upper of two lines, so your prompt doesn't move around. It also left-truncates $PWD if it would otherwise have wrapped to the next line. This version is the same as "termwide," but adds tty information.
Code:
#!/bin/bash
# termwide prompt with tty number
# by Giles - created 2 November 98
#
# $Revision: 1.2 $ $Author: giles $
# $Source: /home/giles/.bashprompt/bashthemes/RCS/twtty,v $
# $Log: twtty,v $
# Revision 1.2 1999/03/25 01:37:51 giles
#
# Revision 1.1 1999/03/25 01:35:26 giles
# Initial revision
#
# This is a variant on "termwide" that incorporates the tty number.
#
# 24 March 99 - use of sed with \{$cut\} where $cut is an integer
# means that this probably now requires a GNU version of sed.
function prompt_command {
TERMWIDTH=${COLUMNS}
# Calculate the width of the prompt:
hostnam=$(echo -n $HOSTNAME | sed -e "s/[\.].*//")
# "whoami" and "pwd" include a trailing newline
usernam=$(whoami)
cur_tty=$(tty | sed -e "s/.*tty\(.*\)/\1/")
newPWD="${PWD}"
# Add all the accessories below ...
let promptsize=$(echo -n "--(${usernam}@${hostnam}:${cur_tty})---(${PWD})--" \
| wc -c | tr -d " ")
let fillsize=${TERMWIDTH}-${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 twtty {
local GRAY="\[\033[1;30m\]"
local LIGHT_GRAY="\[\033[0;37m\]"
local WHITE="\[\033[1;37m\]"
local NO_COLOUR="\[\033[0m\]"
local LIGHT_BLUE="\[\033[1;34m\]"
local YELLOW="\[\033[1;33m\]"
case $TERM in
xterm*)
TITLEBAR='\[\033]0;\u@\h:\w\007\]'
;;
*)
TITLEBAR=""
;;
esac
PS1="$TITLEBAR\
$YELLOW-$LIGHT_BLUE-(\
$YELLOW\$usernam$LIGHT_BLUE@$YELLOW\$hostnam$LIGHT_BLUE:$WHITE\$cur_tty\
${LIGHT_BLUE})-${YELLOW}-\${fill}${LIGHT_BLUE}-(\
$YELLOW\${newPWD}\
$LIGHT_BLUE)-$YELLOW-\
\n\
$YELLOW-$LIGHT_BLUE-(\
$YELLOW\$(date +%H%M)$LIGHT_BLUE:$YELLOW\$(date \"+%a,%d %b %y\")\
$LIGHT_BLUE:$WHITE\$$LIGHT_BLUE)-\
$YELLOW-\
$NO_COLOUR "
PS2="$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR "
}