LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   ZSH - Change default non-root shell symbol from % to $? (https://www.linuxquestions.org/questions/linux-newbie-8/zsh-change-default-non-root-shell-symbol-from-to-%24-4175419601/)

Vryali 07-31-2012 02:24 PM

ZSH - Change default non-root shell symbol from % to $?
 
Currently have a zshrc that has an if statement to set prompt symbol and I just refrain from using the %# when setting things. Was just curious if there's a built-in way to change it so it's the more normal #/$ or if I'm stuck with the if check.

Cheers,

GlennsPref 07-31-2012 06:37 PM

Hi, I have an example that adds colour and different prompt symbols for user and root.

I can't reference the script, lost/forgot.

here is part of,
~/.zshrc....
Code:

# Set a colour prompt #  home
autoload colors zsh/terminfo
if [[ "$terminfo[colors]" -ge 8 ]]; then
    colors
fi
    for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
        eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
        eval PR_LIGHT_$color='%{$fg[${(L)color}]%}'
        (( count = $count + 1 ))
    done
PR_NO_COLOR="%{$terminfo[sgr0]%}"
if [ `whoami` = 'root' ]; then
    PS1="$PR_RED%n$PR_NO_COLOR@$PR_BLUE%m%u$PR_NO_COLOR:$PR_CYAN%2c$PR_RED%(!.#.$) "
else
    PS1="$PR_GREEN%n$PR_NO_COLOR@$PR_BLUE%m%u$PR_NO_COLOR:$PR_CYAN%2c$PR_YELLOW%(!.#.$) "
fi
# Put a clock on the right hand prompt
RPS1="$PR_CYAN(%D{%d-%m %H:%M})$PR_NO_COLOR"

looks like this...
Code:

glenn@GamesBox:~$ su                                                                                    (01-08 09:39)
root@GamesBox:~#                                                                                        (01-08 09:39)

You can add this to the root .zshrc as well.

Hope this helps, for more about zshell and it's use, look up "bash2zsh", "Jerry Peek" https://www.coderanch.com/t/93722/Bo...r-Kiddle-Jerry

And Jerry peek's Magazine articles.

Cheers Glenn


All times are GMT -5. The time now is 10:05 PM.