git-auto-fetch.plugin.zsh 473 Bytes
Newer Older
1
function git_fetch_on_chpwd {
slavaGanzin's avatar
slavaGanzin committed
2
3
4
5
6
7
  ([[ -d .git ]] && [[ ! -f ".git/NO_AUTO_FETCH" ]] && git fetch --all &>! .git/FETCH_LOG &)
}

function git-auto-fetch {
  [[ ! -d .git ]] && return
  if [[ -f ".git/NO_AUTO_FETCH" ]]; then
slavaGanzin's avatar
slavaGanzin committed
8
    rm ".git/NO_AUTO_FETCH" && echo "${fg_bold[red]}disabled${reset_color}"
slavaGanzin's avatar
slavaGanzin committed
9
  else
slavaGanzin's avatar
slavaGanzin committed
10
    touch ".git/NO_AUTO_FETCH" && echo "${fg_bold[green]}enabled${reset_color}"
slavaGanzin's avatar
slavaGanzin committed
11
  fi
12
}
slavaGanzin's avatar
slavaGanzin committed
13
14
chpwd_functions+=(git_fetch_on_chpwd)
git_fetch_on_chpwd
slavaGanzin's avatar
slavaGanzin committed
15
unset git_fetch_on_chpwd