| delorie.com/archives/browse.cgi | search |
| 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:content-type:mime-version:subject:from | |
| :in-reply-to:date:content-transfer-encoding:message-id | |
| :references:to; q=dns; s=default; b=Bldh24UHIiOCb3lcPStKArlVJKYg | |
| cV2tlaUyWmNQCdDf1qkNq+NsR3dgvF2aCR6S9ArDIGEsj2HQZGuQAx7ey1+Gi1z3 | |
| 32iwmV16Lsi51tGLlFQlNk2OLmo76pL66+h/t0djg5GyVSYKonUVWwqRgWbKNGgC | |
| FQ2A9TLGSipfj9I= | |
| 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:content-type:mime-version:subject:from | |
| :in-reply-to:date:content-transfer-encoding:message-id | |
| :references:to; s=default; bh=zyz6yve9TKY4CgxNKUuwkXAwNWs=; b=tE | |
| oaXF76l94udkK+SjEkelNrJFz9hgp1Gp92wTcQ7MVbxRsex1tZMa5FuQz3SKO4rr | |
| Ayd2TLJqzHU6J0mD9lDKvINcicU46KJriblgNv8VjwkVIIcSKVtEJsZOtp5aYsgU | |
| iLjlFzAlF1cVNzbweXjuPqBHR4ko8+5T4uCNEP80Q= | |
| 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=2.7 required=5.0 tests=AWL,BAYES_60,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=GID, anrdaemon AT yandex DOT ru, anrdaemonyandexru, sk:anrdaem |
| X-HELO: | etr-usa.com |
| Mime-Version: | 1.0 (Mac OS X Mail 8.2 \(2104\)) |
| Subject: | Re: Change PS1 when run as administrator |
| From: | Warren Young <wyml AT etr-usa DOT com> |
| In-Reply-To: | <28210846.20160315202354@yandex.ru> |
| Date: | Tue, 15 Mar 2016 13:45:33 -0600 |
| Message-Id: | <B44FA645-36FC-47E5-85BC-2E6A0E0C7F1F@etr-usa.com> |
| References: | <F7CDFE45-BFA7-4599-B510-B40BCA19142F AT etr-usa DOT com> <28210846 DOT 20160315202354 AT yandex DOT ru> |
| To: | cygwin AT cygwin DOT com |
| X-IsSubscribed: | yes |
| X-MIME-Autoconverted: | from quoted-printable to 8bit by delorie.com id u2FJjluN012103 |
On Mar 15, 2016, at 11:23 AM, Andrey Repin <anrdaemon AT yandex DOT ru> wrote:
>
> 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
Here’s a simpler version that’s closer to the stock version in color and style, with the quoting errors fixed:
PS1_COLOR=32
PS1_PCHAR='$'
for group in $(id -G); do
test $group -eq 114 && { PS1_PCHAR='#'; PS1_COLOR=31; break; }
test $group -eq 544 && { PS1_PCHAR='#'; PS1_COLOR=31; break; }
test $group -eq 0 && { PS1_PCHAR='!'; PS1_COLOR=41; break; }
done
PS1='\[\e]0;\w\a\]\n\[\e['$PS1_COLOR'm\]\u@\h '
PS1=$PS1'\[\e[33m\]\w\[\e[0m\]\n'$PS1_PCHAR' '
I’ve split the last line to avoid wrapping.
I’ve gone with the “check engine light” approach to error reporting for the GID=0 case.
If someone wants to apply this to Cygwin’s stock /etc files, it needs to go in /etc/bash.bashrc in Cygwin, not /etc/profile.
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
| webmaster | delorie software privacy |
| Copyright 2019 by DJ Delorie | Updated Jul 2019 |