www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2016/03/15/13:35:39

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:date:from:reply-to:message-id:to:subject
:in-reply-to:references:mime-version:content-type
:content-transfer-encoding; q=dns; s=default; b=e7bzwNW67WrTcdXe
YZ+5IPL80qJ3DQFWcUZwXehKeBT6FhkZAeqnaUqGKDCPfP68KSVSf5LO07HQ1f5v
gsd0ZVNi+dhUgcxWTxBPLWlIheeUKf3LQHnmSozsnxm8pyuTVpACz3Bs+26FrHrb
0B5JL+hhR5jbAlDB7YGutYUz2p0=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:date:from:reply-to:message-id:to:subject
:in-reply-to:references:mime-version:content-type
:content-transfer-encoding; s=default; bh=HtEQor9Y0XPG33D3cesozK
nYZqM=; b=KuQFElNz3sHEi7o/3aRTG5v8lXcIovW+bCNBvvYOlQuMwzgb7VpZl4
voEQwGLqe5SFFEcFElmWw3MzCdbS7w5hos1vk7abE30NZtlUbJu0yNszawve/0p0
iowYTg3HoXOm4jMwi7KLYur/ntGzr13ZJKJssSkstLmLiuoblgKmM=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=4.1 required=5.0 tests=AWL,BAYES_50,FREEMAIL_FROM,KAM_THEBAT,MIME_BASE64_BLANKS,SPF_SOFTFAIL autolearn=no version=3.3.2 spammy=H*UA:Bat!, H*x:Bat!, H*r:sk:postmas, USER
X-HELO: smtp.ht-systems.ru
Date: Tue, 15 Mar 2016 20:23:54 +0300
From: Andrey Repin <anrdaemon AT yandex DOT ru>
Reply-To: cygwin AT cygwin DOT com
Message-ID: <28210846.20160315202354@yandex.ru>
To: Warren Young <wyml AT etr-usa DOT com>, cygwin AT cygwin DOT com
Subject: Re: Change PS1 when run as administrator
In-Reply-To: <F7CDFE45-BFA7-4599-B510-B40BCA19142F@etr-usa.com>
References: <F7CDFE45-BFA7-4599-B510-B40BCA19142F AT etr-usa DOT com>
MIME-Version: 1.0
X-IsSubscribed: yes
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id u2FHZZDx030615

Greetings, Warren Young!

> I just came up with this recipe to change the default PS1 value to use red
> for the user AT host part of the prompt and to change the $ character to a #:

>     if id | grep -qi 'member of administrators group'
>     then
>         export PS1=$(echo "$PS1" | sed -e 's_32_31_' -e 's_\\\$_#_')
>     fi

> I’m not certain the string match on the output of id(1) works everywhere. 
> Is there a better way to check for admin privileges under Cygwin?  You can’t
> check for UID or EUID == 0, for example, as you’d do on a true POSIX system.

> Perhaps something like this should go into the default /etc/profile?

PS1_TAIL="$(
  x="$"
  for group in $(id -G); do 
  {
    test $group -eq 114 && { x="#"; break; }
    test $group -eq 544 && { x="#"; break; }
    test $group -eq 0 && { x="Please remove well-known SID overrides from your /etc/group file#"; break; }
  }
  done
  echo $x
  )"
if [ "$color_prompt" = yes ]; then
    PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\007\]\n$PS1_TAIL '
else
    PS1='\u@\h:\w\007\n$PS1_TAIL '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user AT host:dir
case "$TERM" in
xterm*|rxvt*|putty*)
    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'
    ;;
*)
    ;;
esac


-- 
With best regards,
Andrey Repin
Tuesday, March 15, 2016 20:23:26

Sorry for my terrible english...

- Raw text -


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