My Zsh theme – Forked from Gnzh theme
The theme shows:
– Time
– Path
– Currently used Ruby Version + Gemset (RVM needed)
– Git repo branch + status (Must be inside a git repo)
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
setopt prompt_subst | |
() { | |
local PR_USER PR_USER_OP PR_PROMPT PR_HOST | |
# Check the UID | |
if [[ $UID -ne 0 ]]; then # normal user | |
PR_USER='%F{green}%n%f' | |
PR_USER_OP='%F{green}%#%f' | |
PR_PROMPT='%f➤ %f' | |
else # root | |
PR_USER='%F{red}%n%f' | |
PR_USER_OP='%F{red}%#%f' | |
PR_PROMPT='%F{red}➤ %f' | |
fi | |
# Check if we are on SSH or not | |
if [[ -n "$SSH_CLIENT" || -n "$SSH2_CLIENT" ]]; then | |
PR_HOST='%F{red}%M%f' # SSH | |
else | |
PR_HOST='%F{green}%M%f' # no SSH | |
fi | |
local return_code="%(?..%F{red}%? ↵%f)" | |
local user_host="${PR_USER}%F{cyan}@${PR_HOST}" | |
local curr_t='%B%F{green}%t%f%b' | |
local current_dir="%B%F{blue}%~%f%b" | |
local rvm_ruby='' | |
if ${HOME}/.rvm/bin/rvm-prompt &> /dev/null; then # detect user-local rvm installation | |
rvm_ruby='%B%F{red}‹$(${HOME}/.rvm/bin/rvm-prompt i v g s)›%f%b' | |
elif which rvm-prompt &> /dev/null; then # detect system-wide rvm installation | |
rvm_ruby='%B%F{red}‹$(rvm-prompt i v g s)›%f%b' | |
elif which rbenv &> /dev/null; then # detect Simple Ruby Version Management | |
rvm_ruby='%B%F{red}‹$(rbenv version | sed -e "s/ (set.*$//")›%f$b' | |
fi | |
local git_branch='$(git_prompt_info)' | |
PROMPT="╭─${curr_t} ${current_dir} ${rvm_ruby} ${git_branch} | |
╰─$PR_PROMPT " | |
RPROMPT="${return_code}" | |
ZSH_THEME_GIT_PROMPT_PREFIX="%B%F{cyan}(" | |
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[cyan]%}) %{$fg[green]%}±%f%b" | |
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[cyan]%})%f%b" | |
ZSH_THEME_GIT_PROMPT_SUFFIX="" | |
} |