Change PS1 when run as administrator
Corinna Vinschen
corinna-cygwin@cygwin.com
Tue Mar 15 17:08:00 GMT 2016
On Mar 15 12:33, Andrew Schulman wrote:
> > I just came up with this recipe to change the default PS1 value to use red for the user@host part of the prompt and to change the $ character to a #:
> >
> > if id | grep -qi 'member of administrators group'
> > then
> > export PS1=$(echo "$PS1" | sed -e 's_32_31_' -e 's_\\\$_#_')
> > fi
> >
> > Im not certain the string match on the output of id(1) works everywhere. Is there a better way to check for admin privileges under Cygwin? You cant check for UID or EUID == 0, for example, as youd do on a true POSIX system.
>
> Ha! Yes, there is: see
> https://cygwin.com/ml/cygwin/2015-02/msg00057.html. The magic test is
>
> id -G | grep -qE '\<(544|0)\>'
>
> where 544 is the Administrators group, and 0 is the root group in case the
> old root group entry is present in /etc/group.
>
> For example:
>
> id -G | grep -qE '\<(544|0)\>' && echo admin || echo user
Thou shalt not use the test for gid 0 anymore. If it works, remove the
entry from /etc/group, or better, remove /etc/group entirely. This entry
will render wrong and unwanted results when you least expect them. Such
cruft always does.
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20160315/97cd61e2/attachment.sig>
More information about the Cygwin
mailing list