Change PS1 when run as administrator

Warren Young wyml@etr-usa.com
Tue Mar 15 19:45:00 GMT 2016


On Mar 15, 2016, at 11:23 AM, Andrey Repin <anrdaemon@yandex.ru> wrote:
> 
> PS1_TAIL="$(
>  x="$"
>  for group in $(id -G); do 
>  {
>    test $group -eq 114 && { x="#"; break; }
>    test $group -eq 544 && { x="#"; break; }
>    test $group -eq 0 && { x="Please remove well-known SID overrides from your /etc/group file#"; break; }
>  }
>  done
>  echo $x
>  )"
> if [ "$color_prompt" = yes ]; then
>    PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\007\]\n$PS1_TAIL '
> else
>    PS1='\u@\h:\w\007\n$PS1_TAIL '
> fi
> unset color_prompt force_color_prompt

Here’s a simpler version that’s closer to the stock version in color and style, with the quoting errors fixed:

PS1_COLOR=32
PS1_PCHAR='$'
for group in $(id -G); do
   test $group -eq 114 && { PS1_PCHAR='#'; PS1_COLOR=31; break; }
   test $group -eq 544 && { PS1_PCHAR='#'; PS1_COLOR=31; break; }
   test $group -eq 0   && { PS1_PCHAR='!'; PS1_COLOR=41; break; }
done
PS1='\[\e]0;\w\a\]\n\[\e['$PS1_COLOR'm\]\u@\h '
PS1=$PS1'\[\e[33m\]\w\[\e[0m\]\n'$PS1_PCHAR' '


I’ve split the last line to avoid wrapping.

I’ve gone with the “check engine light” approach to error reporting for the GID=0 case.

If someone wants to apply this to Cygwin’s stock /etc files, it needs to go in /etc/bash.bashrc in Cygwin, not /etc/profile.
--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list