function git_auto_fetch { # auto git fetch on intervals if [[ -d .git ]] || git rev-parse --git-dir 2>/dev/null 1>&2; then # read interval or store default local -i interval if ! interval=$(git config custom.fetch-interval); then ((interval = 24 * 60 * 60)) # 1 day git config custom.fetch-interval $interval fi # Don't fetch if interval is <= 0 (( $interval <= 0 )) && return local -i time=$(date -u +%s) local -i fetch_time=$(git config custom.fetch-time) if (( $time - $fetch_time > $interval )); then echo "Fetching from repositories..." git fetch git config custom.fetch-time $(date -u +%s) fi fi } chpwd_functions+=(git_auto_fetch)