From 08954a63ef39ca9c02f071232ff66cc3f7805aad Mon Sep 17 00:00:00 2001 From: Samir Benmendil Date: Tue, 4 Oct 2016 00:07:31 +0100 Subject: [PATCH] zsh: save interval for autofetch Also allow disabling autofetch by setting interval to 0 or less --- zsh/lib/chpwd.zsh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/zsh/lib/chpwd.zsh b/zsh/lib/chpwd.zsh index 1763cd5..33ca200 100644 --- a/zsh/lib/chpwd.zsh +++ b/zsh/lib/chpwd.zsh @@ -1,7 +1,16 @@ function git_auto_fetch { # auto git fetch on intervals if [[ -d .git ]] || git rev-parse --git-dir 2>/dev/null 1>&2; then - ((interval = 24 * 60 * 60)) # 1 day + # 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 -- 2.48.1