Last active
September 14, 2023 09:20
-
-
Save dragonauta/85fec369a62861c1e06f to your computer and use it in GitHub Desktop.
Zsh prompt change color if normal/root user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This GIST should go inside your .zshrc file | |
# I use same .zshrc for normal and root user, so it's useful to change colors | |
# | |
# It will present PROMPT as: username@hostname dir $ or root@hostname dir # | |
# username on green chars | |
# root on red chars | |
# hostname on bold yellow chars | |
# directories on bold green chars | |
# | |
# RPROMPT should show a clock on the right | |
if [[ $EUID -ne 0 ]]; then | |
PROMPT="%{$fg[green]%}%n%{$fg_bold[white]%}@%{$fg_bold[yellow]%}%m %{$fg_bold[green]%}%1~%{$reset_color%} $ " | |
else | |
PROMPT="%{$fg[red]%}%n%{$fg_bold[white]%}@%{$fg_bold[yellow]%}%m %{$fg_bold[green]%}%1~%{$reset_color%} # " | |
fi | |
RPROMPT='[%T]' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
note that instead of having the whole if block you can do stuff like:
PROMPT='%(!.%F{red}.%F{blue})%m'
same deal for $/#:
%(!.#.$)
documented in section 13.3 Conditional Substrings in Prompts of the zsh manual.
Have a good day!