GitAuto/zsh/GitAuto-fetch.zsh

31 lines
933 B
Bash

git_auto_fetch_interval=${git_auto_fetch_interval:=60}
function git-fetch-all {
(`command git rev-parse --is-inside-work-tree 2>/dev/null` &&
dir=`command git rev-parse --git-dir` &&
[[ ! -f $dir/.no_auto_fetch ]] &&
(( `date +%s` - `date -r $dir/FETCH_LOG +%s 2>/dev/null || echo 0` > $git_auto_fetch_interval )) &&
( GIT_SSH_COMMAND="command ssh -o BatchMode=yes" \
command git fetch >/dev/null 2>&1 & touch $dir/FETCH_LOG & ))
}
function git-auto-fetch {
`command git rev-parse --is-inside-work-tree 2>/dev/null` || return
guard="`command git rev-parse --git-dir`/.no_auto_fetch"
(rm $guard 2>/dev/null &&
echo "${fg_bold[green]}enabled${reset_color}") ||
(touch $guard &&
echo "${fg_bold[red]}disabled${reset_color}")
}
function zle-line-init () {
git-fetch-all
}
if (( $+functions[zle-line-init] )); then
eval "override-git-auto-fetch-$(declare -f zle-line-init)"
fi
zle -N zle-line-init