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:to:from:subject:date:message-id:references :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=DMKzxeAxpnwHsqfO+2PGfjg4r2bRQXpUE1KH6d10LJwC5hM0JgTx4 cdcu0svG+52OWdd3nDEkBt3A2YE3fiOom48H9ZIeOSYBX5VIacMLgaZchThMu7Ts 4rZG0U75Rnb/9bgOxe8N4zJpEGsViCoFSajdPWzsVeR4TeW/QlOz5c= 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:to:from:subject:date:message-id:references :mime-version:content-type:content-transfer-encoding; s=default; bh=MD/P41xcoPN7iFag1i/fhAoMnNs=; b=CNrX2vWusXQcE88jW3CiLxh3OpbW 5ChfDNISEfgsjGL2/eYe3wfBeJF9TUPbYhjiSm953J4PzvLbzVqtWT1a4bZ1/pLU nOXUVmV8LR++ov7CD4ZNuXWeMNRtokDOeRbiLGF1o145Aqud1A7Vl3Wz2Rj2Iqhb 9e9oq2xoQem7pOk= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , 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=0.0 required=5.0 tests=AWL,BAYES_50,RCVD_IN_DNSWL_LOW,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy=ha, U*user, s_32_31_, user AT host X-HELO: plane.gmane.org To: cygwin AT cygwin DOT com From: Andrew Schulman Subject: Re: Change PS1 when run as administrator Date: Tue, 15 Mar 2016 12:33:32 -0400 Lines: 20 Message-ID: <98egebtkn3kakah2g5m9nhr393mag7qm8j@4ax.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Archive: encrypt X-IsSubscribed: yes > 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. Ha! Yes, there is: see https://cygwin.com/ml/cygwin/2015-02/msg00057.html. The magic test is id -G | grep -qE '\<(544|0)\>' where 544 is the Administrators group, and 0 is the root group in case the old root group entry is present in /etc/group. For example: id -G | grep -qE '\<(544|0)\>' && echo admin || echo user -- 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