Being a person who likes to waste countless hours with Linux tweaks, I naturally have to create a custom prompt or two....and of course they are big and obnoxious, yet useful at the same time.
My current prompt is one I've been using for many months, and probably won't remove in the near future. The first function is separate from the prompt itself because I use it with all prompts.
note: If you copy&paste directly from this page into bashrc, it may be broken, since the linebreaks are not always in the proper places.
EDIT: This doesn't work with Busybox...the full gnu-utils package is required.
trunc_pwd() {
# Having a $PWD that wraps to the next line would
# make these funky prompts break up.
# \$(trunc_pwd) is used in place of \w
# How many characters of the $PWD should be kept
local pwdmaxlen=68
# Indicator that there has been directory truncation:
local trunc_symbol=".."
if [ ${#PWD} -gt $pwdmaxlen ]; then
local pwdoffset=$(( ${#PWD} - $pwdmaxlen ))
echo "${trunc_symbol}${PWD:$pwdoffset:$pwdmaxlen}"
else
echo ${PWD}
fi
}
The prompt:
set_promptB() {
# This displays a semi-techy-looking graphical prompt using
# line characters. It uses 8 lines (plus a newline for the cursor)
# in an x terminal, and 9 lines in a linux terminal.
# A proper font which displays line characters is necessary, such as "fixed".
# The prompt displays the following information:
# - Basename of shell's device name and basename of $PWD in the
# titlebar (x term only), eg "4:local" for pts/4:/usr/local
# - Current date and time (linux term only)
# - Shell's device name, eg tty2
# - Physical memory in use (minus buffers/cache)
# - Username@hostname
# - $PWD, truncated after 68 characters to fit on a single line
# - Number of files/total file size in current directory
local C0='\[\033[0m\]' # default foreground color
local C1='\[\033[0;31m\]' # red
local C2='\[\033[1;30m\]' # dark grey
local LN='\[\033(0\]' # lines on
local NL='\[\033(B\]' # lines off
case $TERM in
xterm*|rxvt*)
local TITLEBAR='\[\033]0;\l:\W\007\]'
;;
linux*)
local TITLEBAR='\n \d \@\n'
;;
*)
local TITLEBAR=''
;;
esac
local dir_totals="\$(ls -Al | grep ^- | wc -l | tr -d ' ')/\$(ls -hAl | head -1 | awk '{ print \$2 }')"
local tty=$(tty)
local mem="\$(free -m | grep ^- | awk '{print \$3}')"
#local disk_total="\$(df -h / | grep ^/ | awk '{print \"disk use: \"\$5 \" of \" \$2}')"
# For some reason, using ${LN} followed by a color disables line drawing in
# my vanilla Eterm package, so I've added a ${LN} after each affected color change.
# Also the "a" line character does not work in my Konsole...no big surprise.
# There are a couple of places where I added "\[\]". This is only a failsafe,
# because I noticed vim miscoloring the bracket...thought it might prevent errors.
PS1="${C1}${TITLEBAR}${LN} lqqqqqqqqqqqqqqqqk${NL}${C0}\n\
${C1}${LN}lqj${C2}${LN}lqaqaaaaaaaqaqk ${C1}${LN}mqk${NL}${C0} \n\
${C1}${LN}xa${C2}${LN} mwjlqwqqqqqqqqj ${C1}${LN}qvqq${NL}\[\][ ${tty:5} ]-[ ram use: ${mem}M ]${LN}qq${NL}${C0}\n\
${C1}${LN}mqk${C2}${LN} x tqj ${NL}${C1}\u@\H ${C0} \n\
${C1}${LN}lqj${C2}${LN} x x${NL}${C0} \$(trunc_pwd) \n\
${C1}${LN}xa${C2}${LN} lvkmqqqqqqqqqqqqqqqqqqqqqk ${C1}${LN}qwqq${NL}\[\][ files: ${dir_totals} ]${LN}qq${NL}${C0}\n\
${C1}${LN}mqk${C2}${LN}mqaqaaaaaaaaaaaaaaaaaaqaqj ${C1}${LN}lqj${C0}${NL}\n\
${C1}${LN} mqqqqqqqqqqqqqqqqqqqqqqqqqqqj${NL}${C0}\n"
}
# set the prompt
if [ "${mcON}" = "1" ]; then
# non-funky prompt for midnight commander
# mcON is set from mc alias "export mcON=1; mc -b" (mc.bin in DSL 0.9.0.1)
PS1="[ \@ - \u ] "
else
# change this to desired prompt function
set_promptB
fi