* 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
* Re: Change PS1 when running as administrator
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 19:16 ` Eric Blake
0 siblings, 2 replies; 14+ messages in thread
From: Ernie Rael @ 2014-06-17 16:23 UTC (permalink / raw)
To: cygwin
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 ]]
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? Can use something like
id -G | grep -q "\b544\b"
(or echo ${GROUPS[@]} | ...)
-ernie
--
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
* Re: Change PS1 when running as administrator
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:16 ` Eric Blake
1 sibling, 1 reply; 14+ messages in thread
From: Andrey Repin @ 2014-06-17 16:35 UTC (permalink / raw)
To: Ernie Rael, cygwin
Greetings, Ernie Rael!
> 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 ]]
> 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?
I don't think bash equivalent of test implements Perl RE.
Neither the base test implementation, to that extent.
> Can use something like
> id -G | grep -q "\b544\b"
> (or echo ${GROUPS[@]} | ...)
--
WBR,
Andrey Repin (anrdaemon@yandex.ru) 17.06.2014, <20:30>
Sorry for my terrible english...
--
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
* Re: Change PS1 when running as administrator
2014-06-17 16:35 ` Andrey Repin
@ 2014-06-17 17:22 ` Ernie Rael
2014-06-17 19:17 ` Eric Blake
0 siblings, 1 reply; 14+ messages in thread
From: Ernie Rael @ 2014-06-17 17:22 UTC (permalink / raw)
To: cygwin
On 6/17/2014 9:34 AM, Andrey Repin wrote:
>> [[ $(id -G) =~ \b544\b ]]
>> 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?
> I don't think bash equivalent of test implements Perl RE.
> Neither the base test implementation, to that extent.
I thought, perhaps incorrectly, that \b has been around forever and is
posix.
In any event, looks like
[[ $(id -G) =~ (^| )544($| ) ]]
would work.
--
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
* Re: Change PS1 when running as administrator
2014-06-17 17:22 ` Ernie Rael
@ 2014-06-17 19:17 ` Eric Blake
0 siblings, 0 replies; 14+ messages in thread
From: Eric Blake @ 2014-06-17 19:17 UTC (permalink / raw)
To: cygwin
[-- Attachment #1: Type: text/plain, Size: 831 bytes --]
On 06/17/2014 11:19 AM, Ernie Rael wrote:
> On 6/17/2014 9:34 AM, Andrey Repin wrote:
>
>>> [[ $(id -G) =~ \b544\b ]]
>>> 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?
>> I don't think bash equivalent of test implements Perl RE.
>> Neither the base test implementation, to that extent.
>
> I thought, perhaps incorrectly, that \b has been around forever and is
> posix.
Forever in Linux, but not required by POSIX and not present in BSD (from
which Cygwin inherits its regex implementation).
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Change PS1 when running as administrator
2014-06-17 16:23 ` Ernie Rael
2014-06-17 16:35 ` Andrey Repin
@ 2014-06-17 19:16 ` Eric Blake
1 sibling, 0 replies; 14+ messages in thread
From: Eric Blake @ 2014-06-17 19:16 UTC (permalink / raw)
To: cygwin
[-- Attachment #1: Type: text/plain, Size: 1524 bytes --]
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
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
^ 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
* Re: Change PS1 when running as administrator
2014-06-16 18:40 GrahamC
@ 2014-06-16 19:00 ` Chris J. Breisch
2014-06-16 20:03 ` Frank Fesevur
0 siblings, 1 reply; 14+ messages in thread
From: Chris J. Breisch @ 2014-06-16 19:00 UTC (permalink / raw)
To: cygwin
GrahamC wrote:
> 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.
You might want to look at this thread:
https://sourceware.org/ml/cygwin/2014-04/msg00256.html
I use the registry test, but the id method would also work.
--
Chris J. Breisch
--
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
* Re: Change PS1 when running as administrator
2014-06-16 11:24 Frank Fesevur
@ 2014-06-16 19:06 ` Achim Gratz
2014-06-16 20:05 ` Frank Fesevur
0 siblings, 1 reply; 14+ messages in thread
From: Achim Gratz @ 2014-06-16 19:06 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.
> 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.
Regards,
Achim.
--
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+
Waldorf MIDI Implementation & additional documentation:
http://Synth.Stromeko.net/Downloads.html#WaldorfDocs
--
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
* Re: Change PS1 when running as administrator
2014-06-16 19:06 ` Achim Gratz
@ 2014-06-16 20:05 ` Frank Fesevur
2014-06-17 6:53 ` Thomas Wolff
0 siblings, 1 reply; 14+ messages in thread
From: Frank Fesevur @ 2014-06-16 20:05 UTC (permalink / raw)
To: cygwin
2014-06-16 21:06 GMT+02:00 Achim Gratz:
> 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
--
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
* Re: Change PS1 when running as administrator
2014-06-16 20:05 ` Frank Fesevur
@ 2014-06-17 6:53 ` Thomas Wolff
2014-06-17 7:09 ` Achim Gratz
0 siblings, 1 reply; 14+ messages in thread
From: Thomas Wolff @ 2014-06-17 6:53 UTC (permalink / raw)
To: cygwin
Am 16.06.2014 22:04, schrieb Frank Fesevur:
> 2014-06-16 21:06 GMT+02:00 Achim Gratz:
>> 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.
I can confirm it is localized in German Windows (as I had been told
myself when I proposed the same idea here 2 months ago:) ).
> # 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.
As Corinna had said. Yet, I'd like to check official documentation to
confirm "544" is a constant for this purpose.
Other suggestions had been discussed (like checking something in
/proc/something...).
Thomas
---
Diese E-Mail ist frei von Viren und Malware, denn der avast! Antivirus Schutz ist aktiv.
http://www.avast.com
--
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).