Change PS1 when running as administrator

Eric Blake eblake@redhat.com
Tue Jun 17 19:16:00 GMT 2014


On 06/17/2014 10:21 AM, Ernie Rael wrote:
> On 6/17/2014 1:45 AM, GrahamC wrote:
>> If we are looking for other alternatives the GROUPS environment
>> variable can also be used:
>>
>> PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '
>> for G in "${GROUPS[@]}"; do
>>      if [ "$G" = 544 ]; then
>>          PS1='\[\e]0;Administrator \w\a\]\n\[\e[32m\]\u@\h
>> \[\e[33m\]\w\[\e[0m\]\n# '
>>      fi
>> done
> 
> Speaking of alternatives,
> 
> For matching in bash, something like
> 
>     [[ $(id -G) =~ \b544\b ]]

\b is a glibc regex() extension, not supported in Cygwin regex

Cygwin supports \< as a shortcut for [[:<:]], and \> as a shortcut for
[[:>:]], which are both BSD extensions.  \b is roughly equivalent to
[[:<:][:>:]] - but someone would have to actually patch cygwin's
regcomp.c to enable that extension.

https://cygwin.com/viewvc/src/winsup/cygwin/regex/regcomp.c?view=co&revision=1.16&content-type=text%2Fplain

> 
> was suggested (the suggestion used symbolic name instead of a number and
> didn't use word boundary). Seems like word boundary is needed, but I
> couldn't get this to work. Are the regex boundary matchers not
> supported  by bash =~ operator?

bash only supports what the libc regex() supports, and since Cygwin
regex() is not as full-featured as glibc regex(), the answer is that you
can't use \b in Cygwin bash (yet; PTC).

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 604 bytes
Desc: OpenPGP digital signature
URL: <http://cygwin.com/pipermail/cygwin/attachments/20140617/534c41bf/attachment.sig>


More information about the Cygwin mailing list