l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
October 7: Social gathering
Next Installfest:
TBD
Latest News:
Aug. 18: Discounts to "Velocity" in NY; come to tonight's "Photography" talk
Page last updated:
2001 Dec 30 17:10

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] Help with regular expressions needed.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] Help with regular expressions needed.



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?


LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
O'Reilly and Associates
For numerous book donations.