This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: Change PS1 when run as administrator
- From: Andrew Schulman <schulman dot andrew at epa dot gov>
- To: cygwin at cygwin dot com
- Date: Tue, 15 Mar 2016 12:33:32 -0400
- Subject: Re: Change PS1 when run as administrator
- Authentication-results: sourceware.org; auth=none
- References: <F7CDFE45-BFA7-4599-B510-B40BCA19142F at etr-usa dot com>
> 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
>
> I?m 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 can?t check for UID or EUID == 0, for example, as you?d 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
--
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