public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Cygwin console: Different default background color when terminal runs as Admin?
@ 2023-08-18  2:11 Martin Wege
  2023-08-18  5:26 ` Jonathon Merz
  0 siblings, 1 reply; 7+ messages in thread
From: Martin Wege @ 2023-08-18  2:11 UTC (permalink / raw)
  To: cygwin

Hello,

Just an idea: Could the default background color of the Cygwin console
be changed from black to grey (or RED) if the terminal has been
started with Administrator rights?

Thanks,
Martin

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

* Re: Cygwin console: Different default background color when terminal runs as Admin?
  2023-08-18  2:11 Cygwin console: Different default background color when terminal runs as Admin? Martin Wege
@ 2023-08-18  5:26 ` Jonathon Merz
  2023-08-18  8:11   ` Christian Franke
  2023-08-18  9:51   ` Martin Wege
  0 siblings, 2 replies; 7+ messages in thread
From: Jonathon Merz @ 2023-08-18  5:26 UTC (permalink / raw)
  To: [Cygwin]

[-- Attachment #1: Type: text/plain, Size: 638 bytes --]

On Thu, Aug 17, 2023 at 7:13 PM Martin Wege via Cygwin <cygwin@cygwin.com>
wrote:

> Just an idea: Could the default background color of the Cygwin console
> be changed from black to grey (or RED) if the terminal has been
> started with Administrator rights?
>

Assuming that:
1. The Administrators group is called "Administrators"
2. There aren't any non-administrative groups with "Administrators" in the
name
3. You're using mintty for your terminal

You can run the following in bash or zsh with the desired RGB values:

if [[ `id -Gn` == *Administrators* ]]
then
    echo -ne "\e]11;#FFBBEE\a";
fi

-Jonathon

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

* Re: Cygwin console: Different default background color when terminal runs as Admin?
  2023-08-18  5:26 ` Jonathon Merz
@ 2023-08-18  8:11   ` Christian Franke
  2023-08-18 10:44     ` Thomas Wolff
  2023-08-18  9:51   ` Martin Wege
  1 sibling, 1 reply; 7+ messages in thread
From: Christian Franke @ 2023-08-18  8:11 UTC (permalink / raw)
  To: cygwin

Jonathon Merz via Cygwin wrote:
> On Thu, Aug 17, 2023 at 7:13 PM Martin Wege via Cygwin <cygwin@cygwin.com>
> wrote:
>
>> Just an idea: Could the default background color of the Cygwin console
>> be changed from black to grey (or RED) if the terminal has been
>> started with Administrator rights?
>>
> Assuming that:
> 1. The Administrators group is called "Administrators"
> 2. There aren't any non-administrative groups with "Administrators" in the
> name
> 3. You're using mintty for your terminal
>
> You can run the following in bash or zsh with the desired RGB values:
>
> if [[ `id -Gn` == *Administrators* ]]
> then
>      echo -ne "\e]11;#FFBBEE\a";
> fi

A alternative that should work with any shell, does not rely on 
(unfortunately localized) group names and only assumes that the 
Administrators group S-1-5-32-544 isn't remapped by /etc/group:

case " $(/usr/bin/id -G) " in
   *\ 544\ *) printf '\e]11;#FFFF80\a' ;;
esac

Or use a check of actual access rights:

if [ -r /proc/registry/HKEY_LOCAL_MACHINE/SAM/SAM ]; then ...; fi


I use this in .bashrc to add "(root)" to the default mintty title and 
set '#' as root prompt:

case " $(/usr/bin/id -G) " in
   *\ 544\ *) PS1=${PS1/\\e]0;\\w/\\e]0;\\w (root)}; PS1=${PS1/\\\$ /\# } ;;
esac

-- 
Regards
Christian


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

* Re: Cygwin console: Different default background color when terminal runs as Admin?
  2023-08-18  5:26 ` Jonathon Merz
  2023-08-18  8:11   ` Christian Franke
@ 2023-08-18  9:51   ` Martin Wege
  2023-08-18 11:48     ` Corinna Vinschen
  1 sibling, 1 reply; 7+ messages in thread
From: Martin Wege @ 2023-08-18  9:51 UTC (permalink / raw)
  To: [Cygwin]

On Fri, Aug 18, 2023 at 7:27 AM Jonathon Merz via Cygwin
<cygwin@cygwin.com> wrote:
>
> On Thu, Aug 17, 2023 at 7:13 PM Martin Wege via Cygwin <cygwin@cygwin.com>
> wrote:
>
> > Just an idea: Could the default background color of the Cygwin console
> > be changed from black to grey (or RED) if the terminal has been
> > started with Administrator rights?
> >
>
> Assuming that:
> 1. The Administrators group is called "Administrators"
> 2. There aren't any non-administrative groups with "Administrators" in the
> name
> 3. You're using mintty for your terminal
>
> You can run the following in bash or zsh with the desired RGB values:
>
> if [[ `id -Gn` == *Administrators* ]]
> then
>     echo -ne "\e]11;#FFBBEE\a";
> fi
>

Looking at the output of /usr/bin/id -a was my first guess too. But
this fails quickly because the names are localized. Seriously MS runs
the Windows group names through the l10n wringer!! So what works on
Windows for Germany will surely fail for Windows for Japan. Thus I am
looking for a more portable solution.

Maybe the numeric group ids are more 'portable' across the Windows
versions for different countries?

Thanks,
Martin

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

* Re: Cygwin console: Different default background color when terminal runs as Admin?
  2023-08-18  8:11   ` Christian Franke
@ 2023-08-18 10:44     ` Thomas Wolff
  0 siblings, 0 replies; 7+ messages in thread
From: Thomas Wolff @ 2023-08-18 10:44 UTC (permalink / raw)
  To: cygwin



Am 18.08.2023 um 10:11 schrieb Christian Franke via Cygwin:
> Jonathon Merz via Cygwin wrote:
>> On Thu, Aug 17, 2023 at 7:13 PM Martin Wege via Cygwin 
>> <cygwin@cygwin.com>
>> wrote:
>>
>>> Just an idea: Could the default background color of the Cygwin console
>>> be changed from black to grey (or RED) if the terminal has been
>>> started with Administrator rights?
>>>
>> Assuming that:
>> 1. The Administrators group is called "Administrators"
>> 2. There aren't any non-administrative groups with "Administrators" 
>> in the
>> name
>> 3. You're using mintty for your terminal
>>
>> You can run the following in bash or zsh with the desired RGB values:
>>
>> if [[ `id -Gn` == *Administrators* ]]
>> then
>>      echo -ne "\e]11;#FFBBEE\a";
>> fi
>
> A alternative that should work with any shell, does not rely on 
> (unfortunately localized) group names and only assumes that the 
> Administrators group S-1-5-32-544 isn't remapped by /etc/group:
>
> case " $(/usr/bin/id -G) " in
>   *\ 544\ *) printf '\e]11;#FFFF80\a' ;;
> esac
or like this
case " `id -G` " in
*" 544 "*|*" 0 "*)    echo admin;;
esac
Note the embedding spaces in the case expression.
I'm adding the 0 for a profile portable with Linux.
You could also use
     if id -G | grep -qE '\<(544|0)\>'
at the cost of an additional process creation.
In earlier Windows versions, you could also check for group 547 which 
was some kind of half-admin user.

Thomas

>
> Or use a check of actual access rights:
>
> if [ -r /proc/registry/HKEY_LOCAL_MACHINE/SAM/SAM ]; then ...; fi
>
>
> I use this in .bashrc to add "(root)" to the default mintty title and 
> set '#' as root prompt:
>
> case " $(/usr/bin/id -G) " in
>   *\ 544\ *) PS1=${PS1/\\e]0;\\w/\\e]0;\\w (root)}; PS1=${PS1/\\\$ /\# 
> } ;;
> esac
>


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

* Re: Cygwin console: Different default background color when terminal runs as Admin?
  2023-08-18  9:51   ` Martin Wege
@ 2023-08-18 11:48     ` Corinna Vinschen
  2023-08-18 12:55       ` Christian Franke
  0 siblings, 1 reply; 7+ messages in thread
From: Corinna Vinschen @ 2023-08-18 11:48 UTC (permalink / raw)
  To: cygwin

On Aug 18 11:51, Martin Wege via Cygwin wrote:
> On Fri, Aug 18, 2023 at 7:27 AM Jonathon Merz via Cygwin
> <cygwin@cygwin.com> wrote:
> >
> > On Thu, Aug 17, 2023 at 7:13 PM Martin Wege via Cygwin <cygwin@cygwin.com>
> > wrote:
> >
> > > Just an idea: Could the default background color of the Cygwin console
> > > be changed from black to grey (or RED) if the terminal has been
> > > started with Administrator rights?
> > >
> >
> > Assuming that:
> > 1. The Administrators group is called "Administrators"
> > 2. There aren't any non-administrative groups with "Administrators" in the
> > name
> > 3. You're using mintty for your terminal
> >
> > You can run the following in bash or zsh with the desired RGB values:
> >
> > if [[ `id -Gn` == *Administrators* ]]
> > then
> >     echo -ne "\e]11;#FFBBEE\a";
> > fi
> >
> 
> Looking at the output of /usr/bin/id -a was my first guess too. But
> this fails quickly because the names are localized. Seriously MS runs
> the Windows group names through the l10n wringer!! So what works on
> Windows for Germany will surely fail for Windows for Japan. Thus I am
> looking for a more portable solution.
> 
> Maybe the numeric group ids are more 'portable' across the Windows
> versions for different countries?

Admin group is always Windows SID 1-5-32-544 and gid 544 in Cygwin,
unless somebody overloads the gid values via an /etc/group file.

If you want to be really sure, you have to check every numeric gid
returned by `id -G' if it resolves to SID 1-5-32-544.  You can do
this with the getent(1) tool.


Corinna

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

* Re: Cygwin console: Different default background color when terminal runs as Admin?
  2023-08-18 11:48     ` Corinna Vinschen
@ 2023-08-18 12:55       ` Christian Franke
  0 siblings, 0 replies; 7+ messages in thread
From: Christian Franke @ 2023-08-18 12:55 UTC (permalink / raw)
  To: cygwin

Corinna Vinschen via Cygwin wrote:
> On Aug 18 11:51, Martin Wege via Cygwin wrote:
>> On Fri, Aug 18, 2023 at 7:27 AM Jonathon Merz via Cygwin
>> <cygwin@cygwin.com> wrote:
>>> On Thu, Aug 17, 2023 at 7:13 PM Martin Wege via Cygwin <cygwin@cygwin.com>
>>> wrote:
>>>
>>>> Just an idea: Could the default background color of the Cygwin console
>>>> be changed from black to grey (or RED) if the terminal has been
>>>> started with Administrator rights?
>>>>
>>> Assuming that:
>>> 1. The Administrators group is called "Administrators"
>>> 2. There aren't any non-administrative groups with "Administrators" in the
>>> name
>>> 3. You're using mintty for your terminal
>>>
>>> You can run the following in bash or zsh with the desired RGB values:
>>>
>>> if [[ `id -Gn` == *Administrators* ]]
>>> then
>>>      echo -ne "\e]11;#FFBBEE\a";
>>> fi
>>>
>> Looking at the output of /usr/bin/id -a was my first guess too. But
>> this fails quickly because the names are localized. Seriously MS runs
>> the Windows group names through the l10n wringer!! So what works on
>> Windows for Germany will surely fail for Windows for Japan. Thus I am
>> looking for a more portable solution.
>>
>> Maybe the numeric group ids are more 'portable' across the Windows
>> versions for different countries?
> Admin group is always Windows SID 1-5-32-544 and gid 544 in Cygwin,
> unless somebody overloads the gid values via an /etc/group file.
>
> If you want to be really sure, you have to check every numeric gid
> returned by `id -G' if it resolves to SID 1-5-32-544.  You can do
> this with the getent(1) tool.

Fortunately getent allows multiple keys, so this works:

case "$(getent group $(id -G))" in
   *:S-1-5-32-544:*) echo admin ;;
esac

Unfortunately this may be is slow in domains due to unneeded AD 
requests. Unlike mkgroup, getent output cannot be restricted to local 
groups (and the '-s SERVICE' option is apparently a no-op).

-- 
Regards,
Christian


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

end of thread, other threads:[~2023-08-18 12:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-18  2:11 Cygwin console: Different default background color when terminal runs as Admin? Martin Wege
2023-08-18  5:26 ` Jonathon Merz
2023-08-18  8:11   ` Christian Franke
2023-08-18 10:44     ` Thomas Wolff
2023-08-18  9:51   ` Martin Wege
2023-08-18 11:48     ` Corinna Vinschen
2023-08-18 12:55       ` Christian Franke

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