This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: Change PS1 when run as administrator
- From: Warren Young <wyml at etr-usa dot com>
- To: cygwin at cygwin dot com
- Date: Tue, 15 Mar 2016 13:45:33 -0600
- 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> <28210846 dot 20160315202354 at yandex dot ru>
On Mar 15, 2016, at 11:23 AM, Andrey Repin <anrdaemon@yandex.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