git-auto-fetch.plugin.zsh 979 B

1234567891011121314151617181920212223242526272829303132333435
  1. GIT_AUTO_FETCH_INTERVAL=${GIT_AUTO_FETCH_INTERVAL:=60}
  2. function git-fetch-all {
  3. (`git rev-parse --is-inside-work-tree 2>/dev/null` &&
  4. dir=`git rev-parse --git-dir` &&
  5. [[ ! -f $dir/NO_AUTO_FETCH ]] &&
  6. (( `date +%s` - `date -r $dir/FETCH_LOG +%s 2>/dev/null || echo 0` > $GIT_AUTO_FETCH_INTERVAL )) &&
  7. git fetch --all 2>/dev/null &>! $dir/FETCH_LOG &)
  8. }
  9. function git-auto-fetch {
  10. `git rev-parse --is-inside-work-tree 2>/dev/null` || return
  11. guard="`git rev-parse --git-dir`/NO_AUTO_FETCH"
  12. (rm $guard 2>/dev/null &&
  13. echo "${fg_bold[green]}enabled${reset_color}") ||
  14. (touch $guard &&
  15. echo "${fg_bold[red]}disabled${reset_color}")
  16. }
  17. # Override zle-line-init if it exists
  18. if (( $+functions[zle-line-init] )); then
  19. eval "override-git-auto-fetch-$(declare -f zle-line-init)"
  20. function zle-line-init () {
  21. git-fetch-all
  22. override-git-auto-fetch-zle-line-init
  23. }
  24. else
  25. function zle-line-init () {
  26. git-fetch-all
  27. }
  28. fi
  29. zle -N zle-line-init