git-auto-fetch.plugin.zsh 473 B

123456789101112131415
  1. function git_fetch_on_chpwd {
  2. ([[ -d .git ]] && [[ ! -f ".git/NO_AUTO_FETCH" ]] && git fetch --all &>! .git/FETCH_LOG &)
  3. }
  4. function git-auto-fetch {
  5. [[ ! -d .git ]] && return
  6. if [[ -f ".git/NO_AUTO_FETCH" ]]; then
  7. rm ".git/NO_AUTO_FETCH" && echo "${fg_bold[red]}disabled${reset_color}"
  8. else
  9. touch ".git/NO_AUTO_FETCH" && echo "${fg_bold[green]}enabled${reset_color}"
  10. fi
  11. }
  12. chpwd_functions+=(git_fetch_on_chpwd)
  13. git_fetch_on_chpwd
  14. unset git_fetch_on_chpwd