public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Thomas Wolff <towo@towo.net>
To: cygwin@cygwin.com
Subject: Re: Cygwin console: Different default background color when terminal runs as Admin?
Date: Fri, 18 Aug 2023 12:44:07 +0200	[thread overview]
Message-ID: <8a99139c-45cf-7836-8bd9-ddb15b1e95d0@towo.net> (raw)
In-Reply-To: <37195ea6-c5da-dbbd-55d4-b73cac89589f@t-online.de>



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
>


  reply	other threads:[~2023-08-18 10:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-18  2:11 Martin Wege
2023-08-18  5:26 ` Jonathon Merz
2023-08-18  8:11   ` Christian Franke
2023-08-18 10:44     ` Thomas Wolff [this message]
2023-08-18  9:51   ` Martin Wege
2023-08-18 11:48     ` Corinna Vinschen
2023-08-18 12:55       ` Christian Franke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8a99139c-45cf-7836-8bd9-ddb15b1e95d0@towo.net \
    --to=towo@towo.net \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).