Skip to content

Instantly share code, notes, and snippets.

@dragonauta
Last active September 14, 2023 09:20
Show Gist options
  • Save dragonauta/85fec369a62861c1e06f to your computer and use it in GitHub Desktop.
Save dragonauta/85fec369a62861c1e06f to your computer and use it in GitHub Desktop.
Zsh prompt change color if normal/root user
# 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]'
@xse
Copy link

xse commented Jun 5, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment