zsh/GitAuto-fetch.zsh: init

This commit is contained in:
Oliver Schraml 2019-12-18 14:14:21 +01:00
parent 79c6c22852
commit b940daa0b2
1 changed files with 28 additions and 0 deletions

28
zsh/GitAuto-fetch.zsh Normal file
View File

@ -0,0 +1,28 @@
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