delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2014/06/17/04:45:43

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:message-id:date:from:reply-to:subject:to
:mime-version:content-type:content-transfer-encoding; q=dns; s=
default; b=bWrie7WMckRkwKTvV/mmOpHRTqQtQYDwPXUvQFq4riIYnCD+HvOd5
K8atTzV/4mFPtNuvQqEqk8szIFGCYSJ3lNooR1fArde6rDbgKElv3G8rSFJSHZ82
wb8U51+rK0mTpcsftRUeqbYrxwMNz9PEoph4raB63L9ZVdNqNMGo6E=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:message-id:date:from:reply-to:subject:to
:mime-version:content-type:content-transfer-encoding; s=default;
bh=toRhUR1hiBm/53/SS+UD7PbjgIg=; b=Cvhi0JMEfUXht4EJQvQmCa55CLZr
uPDscNUQMzSWVFVGhWP5JHK/8cAiDqjZ1XFnSLKzAT/38N2vQLLTnXhSW/gtC42J
Ox3iAkM1fdbbUCN1PGOzMb155rW+30FAcLZX/QzgTzRZ93S7eIvrXMfSf2L6TYLy
F+YDCzXoPewmqOk=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=1.4 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,KAM_COUK,RCVD_IN_DNSWL_NONE autolearn=no version=3.3.2
X-HELO: nm38.bullet.mail.ir2.yahoo.com
Message-ID: <1402994703.51470.YahooMailNeo@web172206.mail.ir2.yahoo.com>
Date: Tue, 17 Jun 2014 09:45:03 +0100
From: GrahamC <grahamc001uk AT yahoo DOT co DOT uk>
Reply-To: GrahamC <grahamc001uk AT yahoo DOT co DOT uk>
Subject: Re: Change PS1 when running as administrator
To: "cygwin AT cygwin DOT com" <cygwin AT cygwin DOT com>
MIME-Version: 1.0
X-IsSubscribed: yes
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id s5H8jdIC002385

> Frank Fesevur writes:
>> When I run as administrator I change my PS1 from "$" to "#" with these
>> line in ~/.bashrc.
>>
>> if id -Gn | grep -i Administrators > /dev/null
>
> If anything I'd check for membership in group 544.  "Administrators"
> surely is one of these strings that gets localized depending on the
> phase of the moon or something.  I can't look right now, but I'm pretty
> sure it says "Administratoren" in a german Windows version.

> On all my Dutch Windows all group names are localized apart from
> 544/Administrators.

># id
>uid=1000(Frank) gid=513(Geen)
>groups=513(Geen),0(root),544(Administrators),545(Gebruikers)

>But I agree checking the numeric value is better.

>> If more people like this idea, maybe it could included in /etc/bash.bashrc?
>
> I'll have to think about it, but I lean toward putting it into profile.d
> instead.

>Thanks for considering.
>The other PS1 setting (user AT host dir) is also in bash.bashrc. That's
>why I suggested bash.bashrc.

>Regards,
>Frank

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

Somebody really clever with regular expressions could probably make an equivalent one line test.

--
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


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019