From: Samir Benmendil Date: Mon, 3 Oct 2016 22:41:41 +0000 (+0100) Subject: zsh: auto fetch once a day when entering git repo X-Git-Url: https://git.rmz.io/dotfiles.git/commitdiff_plain/e905a477887c2b36114f465dd7e82b032903bb3c zsh: auto fetch once a day when entering git repo --- diff --git a/zsh/lib/chpwd.zsh b/zsh/lib/chpwd.zsh new file mode 100644 index 0000000..1763cd5 --- /dev/null +++ b/zsh/lib/chpwd.zsh @@ -0,0 +1,14 @@ +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 + 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)