]> git.rmz.io Git - dotfiles.git/blob - zsh/lib/chpwd.zsh
nvim: lazy load mini.clue
[dotfiles.git] / zsh / lib / chpwd.zsh
1 function git_auto_fetch {
2 # auto git fetch on intervals
3 if [[ -d .git ]] || git rev-parse --git-dir 2>/dev/null 1>&2; then
4 # read interval or store default
5 local -i interval
6 if ! interval=$(git config custom.fetch-interval); then
7 ((interval = 24 * 60 * 60)) # 1 day
8 git config custom.fetch-interval $interval
9 fi
10
11 # Don't fetch if interval is <= 0
12 (( $interval <= 0 )) && return
13
14 local -i time=$(date -u +%s)
15 local -i fetch_time=$(git config custom.fetch-time)
16 if (( $time - $fetch_time > $interval )); then
17 echo "Fetching from repositories..."
18 git fetch
19 git config custom.fetch-time $(date -u +%s)
20 fi
21 fi
22 }
23 chpwd_functions+=(git_auto_fetch)