git-auto-fetch.plugin.zsh 1.0 KB

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