This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: Change PS1 when run as administrator
- From: Andrey Repin <anrdaemon at yandex dot ru>
- To: Warren Young <wyml at etr-usa dot com>, cygwin at cygwin dot com
- Date: Tue, 15 Mar 2016 20:23:54 +0300
- Subject: Re: Change PS1 when run as administrator
- Authentication-results: sourceware.org; auth=none
- References: <F7CDFE45-BFA7-4599-B510-B40BCA19142F at etr-usa dot com>
- Reply-to: cygwin at cygwin dot com
Greetings, Warren Young!
> I just came up with this recipe to change the default PS1 value to use red
> for the user@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@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...