public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Re: Change PS1 when running as administrator
@ 2014-06-17  8:45 GrahamC
  2014-06-17 16:23 ` Ernie Rael
  0 siblings, 1 reply; 14+ messages in thread
From: GrahamC @ 2014-06-17  8:45 UTC (permalink / raw)
  To: cygwin

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

^ permalink raw reply	[flat|nested] 14+ messages in thread
* Change PS1 when running as administrator
@ 2014-06-16 18:40 GrahamC
  2014-06-16 19:00 ` Chris J. Breisch
  0 siblings, 1 reply; 14+ messages in thread
From: GrahamC @ 2014-06-16 18:40 UTC (permalink / raw)
  To: cygwin

On Monday, 16 June 2014, 12:25, Frank Fesevur <ffes@users.sourceforge.net> wrote:

> Hi,
> 
> I recently bought a new home computer, so I switched from XP to Win81.
> With Win81 every now and then I need to start cygwin as administrator
> (right click shortcut or tile, run as administrator) to do things that
> I can't do as a normal user.
>
> When I run as administrator I change my PS1 from "$" to "#" with these
> line in ~/.bashrc.
>
> if id -Gn | grep -i Administrators > /dev/null
> then
>    PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n# '
> else
>    PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '
> fi
>
> I don't know if the test can be done a better/easier way, but it works
> for me on a Dutch Win81. I tested it with both 1.7.30 and a recent
> AD/SAM snapshot.
>
> If more people like this idea, maybe it could included in /etc/bash.bashrc?
>
> Regards,
> Frank

Personally I use a test like:  if [ -w /etc ] for this, which works provided a write ACL has not been added for ordinary users on the directory \cygwin\etc. Administrators have write access to this directory.

Bash supports regular expressions, so if [[ `id` =~ Administrators ]] is a shorter test equivalent to your example.

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

^ permalink raw reply	[flat|nested] 14+ messages in thread
* Change PS1 when running as administrator
@ 2014-06-16 11:24 Frank Fesevur
  2014-06-16 19:06 ` Achim Gratz
  0 siblings, 1 reply; 14+ messages in thread
From: Frank Fesevur @ 2014-06-16 11:24 UTC (permalink / raw)
  To: cygwin

Hi,

I recently bought a new home computer, so I switched from XP to Win81.
With Win81 every now and then I need to start cygwin as administrator
(right click shortcut or tile, run as administrator) to do things that
I can't do as a normal user.

When I run as administrator I change my PS1 from "$" to "#" with these
line in ~/.bashrc.

if id -Gn | grep -i Administrators > /dev/null
then
    PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n# '
else
    PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '
fi

I don't know if the test can be done a better/easier way, but it works
for me on a Dutch Win81. I tested it with both 1.7.30 and a recent
AD/SAM snapshot.

If more people like this idea, maybe it could included in /etc/bash.bashrc?

Regards,
Frank

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2014-06-17 19:17 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-17  8:45 Change PS1 when running as administrator GrahamC
2014-06-17 16:23 ` Ernie Rael
2014-06-17 16:35   ` Andrey Repin
2014-06-17 17:22     ` Ernie Rael
2014-06-17 19:17       ` Eric Blake
2014-06-17 19:16   ` Eric Blake
  -- strict thread matches above, loose matches on Subject: below --
2014-06-16 18:40 GrahamC
2014-06-16 19:00 ` Chris J. Breisch
2014-06-16 20:03   ` Frank Fesevur
2014-06-16 11:24 Frank Fesevur
2014-06-16 19:06 ` Achim Gratz
2014-06-16 20:05   ` Frank Fesevur
2014-06-17  6:53     ` Thomas Wolff
2014-06-17  7:09       ` Achim Gratz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).