On Wednesday 19 September 2001 02:33 am, you wrote:
> Now the previous email is an example of a regular expression not
> behaving as planned.
> Or more accurately, the programmer not having planned on it working this
> way.
>
> In my most recent email I gave some sample output that contained my
>
> shell prompt:
> > A sample run (for the last rule):
> > -------------------------------------------------------------------------
> >-----
> >
> > tres@ares:~/program/quick$ ./regexp1.pl regexp1.dat
> >
> > ...
> >
> > tres@ares:~/program/quick$
> > -------------------------------------------------------------------------
> >-----
>
> Mozilla 0.9.2 seems to think this is a valid email address becasue of
> the "@" symbol.
> If you were on my local network then "tres@ares" would be a valid email
> address.
> Mozilla thought that "tres@ares:~/program/quick$" was a valid email
> address.
>
> BAD MOZILLA!!! :-(
>
> Regards,
> Tres
>
> P.S. For the Curious /etc/bashrc contains
>
> export PS1="\u@\h:\w\\$ "
>
> 'username'@'hostname':'current working directory' followed by # for
> root or $ for others
My system bashrc has reached 2.6k.........
I have a few weird prompt hacks to trurnicut the directory length, show my
laptop battery and some color coding.
My code:
<snip>
if [ `/usr/bin/whoami` = "root" ] ; then
PROMPT_COLOR1="1;31"
PROMPT_COLOR2="0;31"
PROMPT_COLOR3="1;37"
PROMPT_COLOR4="0"
else
PROMPT_COLOR1="1;34"
PROMPT_COLOR2="0;34"
PROMPT_COLOR3="1;37"
PROMPT_COLOR4="0"
fi
function prompt_command {
# As much of the response of the "apm" command as is
# necessary to identify the given condition (battery or A/C):
NO_AC_MESG="AC off"
AC_MESG="AC on"
APMD_RESPONSE="$(apm)"
case ${APMD_RESPONSE} in
*${AC_MESG}*)
ACstat="AC"
;;
*${NO_AC_MESG}*)
ACstat="BT"
;;
esac
battery=$(apm | awk '{ print $NF }')
# Turncate the dir to keep it from Wraping.
# When this runs for the first time after logging in
#${COLUMNS} is undefined, this works around it....
if [ ${COLUMNS} \> 0 ] ; then
TERMSIZE=${COLUMNS}
else
TERMSIZE=80
fi
#figure out how big the prompt is.
hostnam=$(hostname -s)
usernam=$(whoami)
temp="$(tty)"
cur_tty="${temp:5}"
unset temp
temp="[${usernam}@${hostnam}]-[${cur_tty}]-[XX ${battery}]-[...]"
# Set the turncaate threshold based on the terminal width
# and the the data in the prompt.
let pwdmaxlen=${TERMSIZE}-${#temp}
unset temp
trunc_symbol="..."
if [ ${#PWD} -gt $pwdmaxlen ]
then
local pwdoffset=$(( ${#PWD} - $pwdmaxlen ))
newPWD="${trunc_symbol}${PWD:$pwdoffset:$pwdmaxlen}"
else
newPWD=${PWD}
fi
}
# PROMPT_COMMAND runs right before the prompt is displayed
PROMPT_COMMAND="prompt_command 2> /dev/null"
# Set the prompt (Big ain't it?)
PS1="\[\033[\${PROMPT_COLOR1}m\][\[\033[\${PROMPT_COLOR2}m\]\u@\h\
\[\033[\${PROMPT_COLOR1}m\]]\[\033[\${PROMPT_COLOR3}m\]-\
\[\033[\${PROMPT_COLOR1}m\][\[\033[\${PROMPT_COLOR2}m\]\
$(tty | sed -e "s:/dev/::")\[\033[\${PROMPT_COLOR1}m\]]\
\[\033[\${PROMPT_COLOR3}m\]-\[\033[\${PROMPT_COLOR1}m\]\
[\[\033[\${PROMPT_COLOR2}m\]\${ACstat} \${battery}\
\[\033[\${PROMPT_COLOR1}m\]]\[\033[\${PROMPT_COLOR3}m\]-\
\[\033[\${PROMPT_COLOR1}m\][\[\033[\${PROMPT_COLOR2}m\]\
\${newPWD}\[\033[\${PROMPT_COLOR1}m\]]\[\033[0m\]\n\
\[\033[\${PROMPT_COLOR4}m\]\\$\[\033[0m\] "
</snip>
Messy, eh?