Skip to content

Instantly share code, notes, and snippets.

@sio2boss
Created April 20, 2015 13:50
Show Gist options
  • Save sio2boss/f480b310b233bd639d69 to your computer and use it in GitHub Desktop.
Save sio2boss/f480b310b233bd639d69 to your computer and use it in GitHub Desktop.
Oh-My-Zsh Av plugin
# AV Plugin from:
#
export __AV_PROMPT_DIR=$ZSH/plugins/av
# Allow for functions in the prompt.
setopt PROMPT_SUBST
## Enable auto-execution of functions.
typeset -ga preexec_functions
typeset -ga precmd_functions
typeset -ga chpwd_functions
# Append git functions needed for prompt.
preexec_functions+='preexec_update_av_vars'
precmd_functions+='precmd_update_av_vars'
chpwd_functions+='chpwd_update_av_vars'
## Function definitions
function preexec_update_av_vars() {
case "$2" in
git*)
__EXECUTED_AV_COMMAND=1
;;
esac
}
function precmd_update_av_vars() {
if [ -n "$__EXECUTED_AV_COMMAND" ]; then
update_current_av_vars
unset __EXECUTED_AV_COMMAND
fi
}
function chpwd_update_av_vars() {
update_current_av_vars
}
function update_current_av_vars() {
unset __CURRENT_AV_STATUS
_AV_STATUS=`av status`
if [ ! -z ${_AV_STATUS} ]; then
__CURRENT_AV_STATUS="av"
fi
}
function prompt_av_info() {
if [ ! -z "$__CURRENT_AV_STATUS" ]; then
echo "%{${fg[green]}%}$__CURRENT_AV_STATUS%{${fg[default]}%}"
fi
}
# Set the prompt.
RPROMPT='$(prompt_av_info)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment