git-auto-fetch.plugin.zsh 812 B

123456789101112131415161718192021222324252627
  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 &>! $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. eval "override-git-auto-fetch-$(declare -f zle-line-init)"
  18. function zle-line-init () {
  19. git-fetch-all
  20. override-git-auto-fetch-zle-line-init
  21. }
  22. zle -N zle-line-init