Skip to content

Instantly share code, notes, and snippets.

@jstn
Created August 23, 2017 11:33
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 jstn/d249cc4bbb76e0e06ccc6d6a11ff5f04 to your computer and use it in GitHub Desktop.
Save jstn/d249cc4bbb76e0e06ccc6d6a11ff5f04 to your computer and use it in GitHub Desktop.
function git_prompt() {
local dirty=""
if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then
dirty="*"
fi
if ! git diff --quiet 2> /dev/null; then
dirty="*"
fi
local ref
ref=$(git symbolic-ref --quiet HEAD 2> /dev/null)
local ret=$?
if [[ $ret != 0 ]]; then
[[ $ret == 128 ]] && return
ref=$(git rev-parse --short HEAD 2> /dev/null) || return
fi
echo " %F{cyan}${ref#refs/heads/}%f%F{red}${dirty}%f"
}
setopt PROMPT_SUBST
export PROMPT='[%n@%F{yellow}%m%f:%F{blue}%~%f$(git_prompt)]%# '
export RPROMPT='[%D %*]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment