12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- : ${GIT_AUTO_FETCH_INTERVAL:=60}
- zmodload zsh/datetime zsh/stat
- function git-fetch-all {
- (
-
- if ! gitdir="$(command git rev-parse --git-dir 2>/dev/null)"; then
- return 0
- fi
-
- if [[ -z "$gitdir" || -f "$gitdir/NO_AUTO_FETCH" ]]; then
- return 0
- fi
-
- lastrun="$(zstat +mtime "$gitdir/FETCH_LOG" 2>/dev/null || echo 0)"
-
- if (( EPOCHSECONDS - lastrun < $GIT_AUTO_FETCH_INTERVAL )); then
- return 0
- fi
-
- GIT_SSH_COMMAND="command ssh -o BatchMode=yes" \
- command git fetch --all 2>/dev/null &>! "$gitdir/FETCH_LOG"
- ) &|
- }
- function git-auto-fetch {
-
- command git rev-parse --is-inside-work-tree &>/dev/null || return 0
-
- local guard="$(command git rev-parse --git-dir)/NO_AUTO_FETCH"
- if [[ -f "$guard" ]]; then
- command rm "$guard" && echo "${fg_bold[green]}enabled${reset_color}"
- else
- command touch "$guard" && echo "${fg_bold[red]}disabled${reset_color}"
- fi
- }
- (( ! ${+functions[_git-auto-fetch_zle-line-init]} )) || return 0
- case "$widgets[zle-line-init]" in
-
- builtin|"") function _git-auto-fetch_zle-line-init() {
- git-fetch-all
- } ;;
-
- user:*) zle -N _git-auto-fetch_orig_zle-line-init "${widgets[zle-line-init]#user:}"
- function _git-auto-fetch_zle-line-init() {
- git-fetch-all
- zle _git-auto-fetch_orig_zle-line-init -- "$@"
- } ;;
- esac
- zle -N zle-line-init _git-auto-fetch_zle-line-init
|