X-Recipient: archive-cygwin@delorie.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B7ADD385042A
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
	s=default; t=1692355461;
	bh=7ekFSUD4PDD+jyrUnn+m+1QNSuQwJ2Kj7ZyYhly36oU=;
	h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe:
	 List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:
	 From;
	b=EmqdSpEjhTNYI/LSU7FNmT3I+r/0bIdrB3Gv3KwMZj+LjBDdlZ+Lfiv8QdSjd955u
	 3A2h06YJrM6m3IJSOkr2JbvEO1uoFwZEGtfPnHoOwUDERJjhIRRZOWkSdRTtPYanMt
	 vFNRR5AduahGlqrF8j7vGPI+w2zuXDgpEOQql2F8=
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5FA6C3858401
Message-ID: <8a99139c-45cf-7836-8bd9-ddb15b1e95d0@towo.net>
Date: Fri, 18 Aug 2023 12:44:07 +0200
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
 Thunderbird/102.14.0
Subject: Re: Cygwin console: Different default background color when terminal
 runs as Admin?
To: cygwin@cygwin.com
References: <CANH4o6PFnrVbi7TkRn26Q7Sk24fcftZvavwF4vhV9sxFM4MmVQ@mail.gmail.com>
 <CAB7+T8gVwQtR3XZ6FvAtOkHwZ0AVPzzPOtk2JTA9HBvNQiBfdQ@mail.gmail.com>
 <37195ea6-c5da-dbbd-55d4-b73cac89589f@t-online.de>
In-Reply-To: <37195ea6-c5da-dbbd-55d4-b73cac89589f@t-online.de>
X-Provags-ID: V03:K1:GCRPpPul/NeRmfk+4cANiUklkgbeKUWx8QrEQa5vvTjtQR95Zvn
 FtsZK1HK2CLy3PA5hgr4sfxh/KjJxzLBniNBme/9gcxHplxhWYaqLFF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ONN2Lkdo32CXN
 AFaULTjA1VlKYNg==
X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00, BODY_8BITS,
 KAM_DMARC_STATUS, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,
 RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS,
 TXREP autolearn=ham autolearn_force=no version=3.4.6
X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on
 server2.sourceware.org
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.29
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
From: Thomas Wolff via Cygwin <cygwin@cygwin.com>
Reply-To: Thomas Wolff <towo@towo.net>
Content-Type: text/plain; charset="utf-8"; Format="flowed"
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie.com@cygwin.com>
Content-Transfer-Encoding: 8bit
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 37IAiMq7014303



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
>


-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

