This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Change PS1 when run as administrator

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?

  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; }
  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 '
    PS1='\u@\h:\w\007\n$PS1_TAIL '
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'

With best regards,
Andrey Repin
Tuesday, March 15, 2016 20:23:26

Sorry for my terrible english...

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]