Cygwin console: Different default background color when terminal runs as Admin?

Christian Franke Christian.Franke@t-online.de
Fri Aug 18 08:11:43 GMT 2023


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



More information about the Cygwin mailing list