Skip to content

Instantly share code, notes, and snippets.

@ncuesta
Last active July 16, 2018 12:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ncuesta/20f1652ec86202c72bc2 to your computer and use it in GitHub Desktop.
Save ncuesta/20f1652ec86202c72bc2 to your computer and use it in GitHub Desktop.
Personal theme for zsh prompts
# vim:ft=zsh ts=2 sw=2 sts=2
# Original theme taken from https://github.com/jackharrisonsherlock/common - all credit goes to @jackharrisonsherlock
# Just copied this to further customize it.
# Prompt symbol
COMMON_PROMPT_SYMBOL="❯"
# Left Prompt
PROMPT='$(common_host)$(common_current_dir)$(common_rb_version)$(common_return_status)'
# Right Prompt
RPROMPT='$(common_git_status)'
# Prompt with current SHA
# PROMPT='$(common_host)$(common_current_dir)$(common_rb_version)$(common_return_status)'
# RPROMPT='$(common_git_status) $(git_prompt_short_sha)'
# Host
common_host() {
if [[ -n $SSH_CONNECTION ]]; then
me="%n@%m"
elif [[ $LOGNAME != $USER ]]; then
me="%n"
fi
if [[ -n $me ]]; then
echo "%{$fg[green]%}$me%{$reset_color%}:"
fi
if [[ $AWS_VAULT ]]; then
echo "%{$fg[yellow]%}$AWS_VAULT%{$reset_color%} "
fi
}
# Current directory
common_current_dir() {
echo -n "%{$fg[blue]%}%c "
}
# Prompt symbol
common_return_status() {
echo -n "%(?.%F{magenta}.%F{red})$COMMON_PROMPT_SYMBOL%f "
}
# Git status
common_git_status() {
local message=""
local message_color="%F{green}"
local staged=$(git status --porcelain 2>/dev/null | grep -e "^M " -e "^A ")
local unstaged=$(git status --porcelain 2>/dev/null | grep -e "^ M" -e "^??")
if [[ -n ${staged} ]]; then
message_color="%F{red}"
elif [[ -n ${unstaged} ]]; then
message_color="%F{yellow}"
fi
local branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
if [[ -n ${branch} ]]; then
message+="${message_color}${branch}%f"
fi
echo -n "${message}"
}
# Git prompt SHA
ZSH_THEME_GIT_PROMPT_SHA_BEFORE="%{%F{green}%}"
ZSH_THEME_GIT_PROMPT_SHA_AFTER="%{$reset_color%} "
# Ruby version
common_rb_version() {
rb_version="%{$fg[yellow]%}($(rbenv version-name)) "
echo -n $rb_version
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment