This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Change PS1 when run as administrator


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]