[ale] $PS1 stuff

David S. Jackson dsj at dsj.net
Mon Apr 12 12:37:27 EDT 1999


Thanks to everybody who responded!  

I actually found what I was looking for when I found a little proggie called
"bashprompt".  It's at http://bash.current.nu.  It's just a collection of
shell functions, but it was a little too complicated for my tastes, so I
built a shell function of my own into my bashrc.  I call it bp() (for
bashprompt doh!) :


=========================SNIP=======================================

bp()
{
clear; echo -e "\n                 Bash Prompt Themes: \n blue, combo, cyan,
elite, elite2, fire, green, \nmagenta, red, redhat, suse, white, yellow,
friendly, spiffy  \n\n" 
read pchoice

case "$pchoice" in
  blue) PS1="\[\033[34;44;1m\]\333\262\261\260\[\033[37;44;1m\]\u@\h\[\033[0m\]\
\[\033[34;40m\]\333\262\261\260\[\033[37;40;1m\] \ \d \$(date +%I:%M:%S%P)
\n\[\033[34;40;1m\]\w/\[\033[0m\] "
        PS2="\[\033[34;40m\]\333\262\261\260\[\033[0m\]>"
  ;;
  combo) PS1="\[\033[01;34;01m\]\333\262\261\260\[\033[01;37;44m\]\u@\h\[\033[00;34;40m\]\260\261\262\333\[\033[00;34;40m\]\333\262\261\260\[\033[01;37;40m\]\d\$(date+%I:%M:%S%P)\n\[\033[01;33;40m\]$PWD>\[\033[00m\]"
         PS2="\[\033[01;34;01m\]\333\262\261\260\[\033[00;34;40m\]\260\261\262\333\[\033[00;34;40m\]\333\262\261\260\[\033[01;01;34m\]>\[\033[00m\]"
  ;;
  cyan) PS1="\[\033[36;46;1m\]\333\262\261\260\[\033[37;46;1m\]\u@\h\[\033[0m\033[36;40m\]\333\262\261\260\[\033[37;40;1m\]\d\$(date+%I:%M:%S%P)\n\[\033[36;40;1m\]\w/\[\033[0m\]"
        PS2="\[\033[36;40m\]\333\262\261\260\[\033[0m\]>"
  ;;
  elite) PS1="\[\033[31m\]\332\304\[\033[34m\](\[\033[31m\]\u\[\033[34m\]@\[\033[31m\]\h\[\033[34m\])\[\033[31m\]-\[\033[34m\](\[\033[31m\]\$(date+%I:%M%P)\[\033[34m\]-:-\[\033[31m\]\$(date+%m)\[\033[34m\033[31m\]/\$(date+%d)\[\033[34m\])\[\033[31m\]\304-\[\033[34m]\\371\[\033[31m\]-\371\371\[\033[34m\]\372\n\[\033[31m\]\300\304\[\033[34m\](\[\033[31m\]\W\[\033[34m\])\[\033[31m\]\304\371\[\033[34m\]\372\[\033[00m\]"
         PS2="> "
  ;;
  elite2) local GRAD1=tty|cut -d/ -f3
          
          localCOLOR1="\[\033[0;36m\]"
          local COLOR2="\[\033[1;36m\]"
          local COLOR3="\[\033[1;30m\]"
	  local COLOR4="\[\033[0m\]"
          PS1="$COLOR3Ú$COLOR1Ä$COLOR2($COLOR1\u$COLOR3@$COLOR1\h$COLOR2)$COLOR1Ä$COLOR2($COLOR1\#$COLOR3/$COLOR1$GRAD1$COLOR2)$COLOR1Ä$COLOR2($COLOR1\$(date+%I:%M%P)$COLOR3:$COLOR1\$(date+%m/%d/%y)$COLOR2)$COLOR1Ä$COLOR3-$COLOR4\n$COLOR3À$COLOR1Ä$COLOR2($COLOR1\$$COLOR3:$COLOR1\w$COLOR2)$COLOR1Ä$COLOR3-$COLOR4"
          PS2="$COLOR2Ä$COLOR1Ä$COLOR3-$COLOR4 "
  ;;
  fire)  local GRAD1='\[\333\262\261\260\]'
         local GRAD2='\[\260\261\262\333\]'
         local COLOR1='\[\033[01;33;43m\]'
         local COLOR2='\[\033[01;37;43m\]'
         local COLOR3='\[\033[00;31;43m\]'
         local COLOR4='\[\033[00;31;40m\]'
         local COLOR5='\[\033[01;33;40m\]'
         local COLOR6='\[\033[01;37;40m\]'
         local GRAD0='\[\033[00m\]'
	 
	 PS1=$COLOR1$GRAD1$COLOR2'\u@\h'$COLOR3$GRAD2$COLOR4$GRAD1\
            $COLOR6' \d \$(date +%I:%M:%S%P) '$NONE'\n'$COLOR5'\w/'$GRAD0' '
         PS2=$COLOR1$GRAD1$COLOR3$GRAD2$COLOR4$GRAD1$COLOR5'>'$GRAD0' '
  ;;
  green) PS1="\[\033[32;42;1m\]\333\262\261\260\[\033[37;42;1m\]\u@\h\[\033[0m\033[32;40m\]\333\262\261\260\[\033[37;40;1m\]\d\$(date+%I:%M:%S%P)\n\[\033[32;40;1m\]\w/\[\033[0m\]"
         PS2="\[\033[32;40m\]\333\262\261\260\[\033[0m\]>"
  ;;
  magenta) PS1="\[\033[35;45;1m\]\333\262\261\260\[\033[37;45;1m\]\u@\h\[\033[0m\033[35;40m\]\333\262\261\260\[\033[37;40;1m\]\d\$(date+%I:%M:%S%P)\n\[\033[35;40;1m\]\w/\[\033[0m\]"
           PS2="\[\033[35;40m\]\333\262\261\260\[\033[0m\]>"
  ;;
  red) PS1="\[\033[31;41;1m\]\333\262\261\260\[\033[37;41;1m\]\u@\h\[\033[0m\033[31;40m\]\333\262\261\260\[\033[37;40;1m\]\d\$(date+%I:%M:%S%P)\n\[\033[31;40;1m\]\w/\[\033[0m\]"
       PS2="\[\033[31;40m\]\333\262\261\260\[\033[0m\]>"
  ;;
  redhat)  PS1="[\u@\h \W]\\$ "
           PS2="> "
  ;;
  suse)   PS1="\u@\h:\w/ > "
          PS2="> "
  ;;
  white) PS1="\[\033[37;47;1m\]\333\262\261\260\[\033[37;47;1m\]\u@\h\[\033[0m\033[37;40m\]\333\262\261\260\[\033[37;40;1m\]\d\$(date+%I:%M:%S%P)\n\[\033[37;40;1m\]\w/\[\033[0m\]"
         PS2="\[\033[37;40m\]\333\262\261\260\[\033[0m\]>"
  ;;
  yellow) PS1="\[\033[33;43;1m\]\333\262\261\260\[\033[37;43;1m\]\u@\h\[\033[0m\033[33;40m\]\333\262\261\260\[\033[37;40;1m\]\d\$(date+%I:%M:%S%P)\n\[\033[33;40;1m\]\w/\[\033[0m\]"
          PS2="\[\033[33;40m\]\333\262\261\260\[\033[0m\]>"
  ;;
  friendly)  PS1="Time: \d \t  Hi \u@\h You are in -> \w \n Cmd:\# His: \!]\$ "
  ;;
  spiffy)  PS1="\[\033[0;35m\] \$(sd) \[\033[0;31m\] \u@\h \[\033[0;36m\] c: \#  h: \!  \n\[\033[1;32m\] \w]\$ \[\033[0m\] "
  ;;
  *)  echo -e "\nPlease type your answer exactly as it appears on the list
above.\n\n"
  ;;
  esac
    
  export PS1 PS2
    
}
    
===========================SNIP====================================


The kicker for me was getting my fonts sqared away.  I kept on issuing
escape codes that didn't display as promised.  I later found out that I had
to use VGA pcf fonts and nothing else.  I installed sabvga, adjusted my
.Xdefaults, and now it seems to work quite well.  The fonts were why it
wasn't working on bash 1.14.7 before.  Also because you have to use
\[\033[??;??m\] for the ANSI color escapes on pre 2.0 bash builds.  \e alone
won't do it.  (works fine on greater than 2.0 though.)

Thanks to all who pointed me to many and various places for number
conversion.  The ASCII manpage, the ISO_8890_1 man page, and the xfd utility
also.  Going xfd -fn sabvga (or whatever fontname) has been a big help.

Anyway, I feel like I have a workable grasp of this thing now; my first two
prompts are "friendly" and "spiffy" above.  Let me know if you like them,
okay?

--
David S. Jackson                           http://www.dsj.net
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
"You may satisfy all your senses and still not be satisfied."
                        --Edward S. Martin






More information about the Ale mailing list