delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2023/08/18/04:12:10

X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9644A3860769
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1692346328;
bh=i+9YaGyQINFBmKzBDG3At5tinkBEyxm/UOIFHV4Yz4w=;
h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe:
List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:
From;
b=bZ02GgY7bIiKyp5OWE8H7H5S4rgynFvTU3jDwAAfL19DJa8Gq4LoGXZXLVM+serDz
7P0VzmNhjuvCeleirPQuUwTwIykddw7tSIO8ywsbkevJtbEL0Uo4olD62xeiAm2yO/
t3VaQWlqgD2qnNIAsLXXj1gywUJ9mY7BFUcHKirM=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D21A5385B512
Subject: Re: Cygwin console: Different default background color when terminal
runs as Admin?
To: cygwin <cygwin AT cygwin DOT com>
References: <CANH4o6PFnrVbi7TkRn26Q7Sk24fcftZvavwF4vhV9sxFM4MmVQ AT mail DOT gmail DOT com>
<CAB7+T8gVwQtR3XZ6FvAtOkHwZ0AVPzzPOtk2JTA9HBvNQiBfdQ AT mail DOT gmail DOT com>
Message-ID: <37195ea6-c5da-dbbd-55d4-b73cac89589f@t-online.de>
Date: Fri, 18 Aug 2023 10:11:43 +0200
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
SeaMonkey/2.53.16
MIME-Version: 1.0
In-Reply-To: <CAB7+T8gVwQtR3XZ6FvAtOkHwZ0AVPzzPOtk2JTA9HBvNQiBfdQ@mail.gmail.com>
X-TOI-EXPURGATEID: 150726::1692346306-F4FE1704-A43514F2/0/0 CLEAN NORMAL
X-TOI-MSGID: f0668a7c-3c35-4cd1-9572-55ccd0a91989
X-Spam-Status: No, score=-6.0 required=5.0 tests=BAYES_00, FREEMAIL_FROM,
KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, NICE_REPLY_A, RCVD_IN_DNSWL_NONE,
RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE,
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 AT cygwin DOT com
X-Mailman-Version: 2.1.29
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
From: Christian Franke via Cygwin <cygwin AT cygwin DOT com>
Reply-To: Christian Franke <Christian DOT Franke AT t-online DOT de>
Errors-To: cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com>
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 37I8C9j4006087

Jonathon Merz via Cygwin wrote:
> On Thu, Aug 17, 2023 at 7:13 PM Martin Wege via Cygwin <cygwin AT cygwin DOT 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


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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019