delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2014/06/16/14:40:52

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:message-id:date:from:reply-to:subject:to
:mime-version:content-type:content-transfer-encoding; q=dns; s=
default; b=UnOsmWpe+C2DAP4jslTEDuqWkJnoI8U22M8pGy8F89QcGChbNv8bd
0E4Ll4JtHDb1cVEARsXXsixjlPhdGg2rvGLg9TcZ3N9JjqqLGNNMWTP5eQPU+VMd
UmzstC7l8uiRo1PAq+a5OpAMcQIggWJRQ2hHvEu2kG/TBzjCnZoXNM=
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:message-id:date:from:reply-to:subject:to
:mime-version:content-type:content-transfer-encoding; s=default;
bh=3EjQYchusuTpeko0EZbxuT7GG9A=; b=swiCVn17CZ7438Nd4deHYf5e64he
jVdbRkM+iacRB2Y9t5olM0bJrbMiLHngCWONwXkSTBY2i5YaZCYs9QvLKonCqYDd
TazsJ1BcIFSi1SrPFuu+1WqCVn2RAAJHFUdQT0ENfJQRbpXwhbLvN7ofr/VLLpZN
ko9TjhpDcWKsZXc=
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=3.2 required=5.0 tests=AWL,BAYES_50,FREEMAIL_FROM,KAM_COUK,RCVD_IN_DNSWL_NONE autolearn=no version=3.3.2
X-HELO: nm4-vm6.bullet.mail.ir2.yahoo.com
Message-ID: <1402944031.26368.YahooMailNeo@web172202.mail.ir2.yahoo.com>
Date: Mon, 16 Jun 2014 19:40:31 +0100 (BST)
From: GrahamC <grahamc001uk AT yahoo DOT co DOT uk>
Reply-To: GrahamC <grahamc001uk AT yahoo DOT co DOT uk>
Subject: Change PS1 when running as administrator
To: "cygwin AT cygwin DOT com" <cygwin AT cygwin DOT com>
MIME-Version: 1.0
X-IsSubscribed: yes
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id s5GIemYp023761

On Monday, 16 June 2014, 12:25, Frank Fesevur <ffes AT users DOT sourceforge DOT net> wrote:

> Hi,
> 
> I recently bought a new home computer, so I switched from XP to Win81.
> With Win81 every now and then I need to start cygwin as administrator
> (right click shortcut or tile, run as administrator) to do things that
> I can't do as a normal user.
>
> When I run as administrator I change my PS1 from "$" to "#" with these
> line in ~/.bashrc.
>
> if id -Gn | grep -i Administrators > /dev/null
> then
>    PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n# '
> else
>    PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '
> fi
>
> I don't know if the test can be done a better/easier way, but it works
> for me on a Dutch Win81. I tested it with both 1.7.30 and a recent
> AD/SAM snapshot.
>
> If more people like this idea, maybe it could included in /etc/bash.bashrc?
>
> Regards,
> Frank

Personally I use a test like:  if [ -w /etc ] for this, which works provided a write ACL has not been added for ordinary users on the directory \cygwin\etc. Administrators have write access to this directory.

Bash supports regular expressions, so if [[ `id` =~ Administrators ]] is a shorter test equivalent to your example.

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


- Raw text -


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