Cygwin console: Different default background color when terminal runs as Admin?
Christian Franke
Christian.Franke@t-online.de
Fri Aug 18 12:55:46 GMT 2023
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
More information about the Cygwin
mailing list