2016-11-16 06:06:41 -08:00
|
|
|
#!/usr/bin/env zsh
|
2017-10-03 10:55:26 -07:00
|
|
|
# Loosely based off Pure <https://github.com/sindresorhus/pure>
|
2015-12-20 20:39:11 -08:00
|
|
|
|
|
|
|
_strlen() { echo ${#${(S%%)1//$~%([BSUbfksu]|([FB]|){*})/}}; }
|
|
|
|
|
|
|
|
# fastest possible way to check if repo is dirty
|
|
|
|
prompt_git_dirty() {
|
2015-12-22 01:04:31 -08:00
|
|
|
is-callable git || return
|
|
|
|
|
2015-12-20 20:39:11 -08:00
|
|
|
# check if we're in a git repo
|
|
|
|
[[ "$(command git rev-parse --is-inside-work-tree 2>/dev/null)" == "true" ]] || return
|
|
|
|
# check if it's dirty
|
|
|
|
command test -n "$(git status --porcelain --ignore-submodules -unormal)" || return
|
|
|
|
|
|
|
|
local r=$(command git rev-list --right-only --count HEAD...@'{u}' 2>/dev/null)
|
|
|
|
local l=$(command git rev-list --left-only --count HEAD...@'{u}' 2>/dev/null)
|
|
|
|
|
|
|
|
(( ${r:-0} > 0 )) && echo -n " %F{green}${r}⇣"
|
|
|
|
(( ${l:-0} > 0 )) && echo -n " %F{yellow}${l}⇡"
|
|
|
|
echo -n '%f'
|
|
|
|
}
|
|
|
|
|
|
|
|
## Hooks ###############################
|
|
|
|
prompt_hook_precmd() {
|
|
|
|
vcs_info # get git info
|
2017-07-17 11:59:25 -07:00
|
|
|
# Newline before prompt, except on init
|
2017-10-03 10:55:26 -07:00
|
|
|
[[ $PROMPT_DONE ]] && print ""; PROMPT_DONE=1
|
2015-12-20 20:39:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
## Initialization ######################
|
|
|
|
prompt_init() {
|
2017-10-03 10:55:26 -07:00
|
|
|
# prevent the extra space in the rprompt
|
|
|
|
[[ $EMACS ]] || ZLE_RPROMPT_INDENT=0
|
|
|
|
# prevent percentage showing up
|
|
|
|
# if output doesn't end with a newline
|
|
|
|
export PROMPT_EOL_MARK=
|
2015-12-20 20:39:11 -08:00
|
|
|
|
2017-07-17 11:59:25 -07:00
|
|
|
# prompt_opts=(cr subst percent)
|
2015-12-20 20:39:11 -08:00
|
|
|
setopt PROMPTSUBST
|
|
|
|
autoload -Uz add-zsh-hook
|
|
|
|
autoload -Uz vcs_info
|
|
|
|
|
|
|
|
add-zsh-hook precmd prompt_hook_precmd
|
|
|
|
# Updates cursor shape and prompt symbol based on vim mode
|
|
|
|
zle-keymap-select() {
|
|
|
|
case $KEYMAP in
|
2017-07-17 11:59:25 -07:00
|
|
|
vicmd) PROMPT_SYMBOL="%F{magenta}## " ;;
|
|
|
|
main|viins) PROMPT_SYMBOL="%(?.%F{blue}.%F{red})λ " ;;
|
2015-12-20 20:39:11 -08:00
|
|
|
esac
|
|
|
|
zle reset-prompt
|
|
|
|
zle -R
|
|
|
|
}
|
|
|
|
zle -N zle-keymap-select
|
|
|
|
zle -A zle-keymap-select zle-line-init
|
|
|
|
|
|
|
|
zstyle ':vcs_info:*' enable git
|
|
|
|
zstyle ':vcs_info:*' use-simple true
|
|
|
|
zstyle ':vcs_info:*' max-exports 2
|
2017-10-03 10:55:26 -07:00
|
|
|
zstyle ':vcs_info:git*' formats '%b'
|
|
|
|
zstyle ':vcs_info:git*' actionformats '%b (%a)'
|
2015-12-20 20:39:11 -08:00
|
|
|
|
2017-01-08 17:29:49 -08:00
|
|
|
# show username@host if logged in through SSH
|
2017-07-17 11:59:25 -07:00
|
|
|
[[ $SSH_CONNECTION ]] && prompt_username='%F{magenta}%n%F{244}@%m '
|
2015-12-22 01:04:31 -08:00
|
|
|
|
2017-07-17 11:59:25 -07:00
|
|
|
RPROMPT='%F{cyan}%~ %F{magenta}${vcs_info_msg_0_}$(prompt_git_dirty)%f'
|
|
|
|
PROMPT='${prompt_username}${PROMPT_SYMBOL:-$ }'
|
2015-12-20 20:39:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
prompt_init "$@"
|