]> git.rmz.io Git - dotfiles.git/commitdiff
zsh: auto fetch once a day when entering git repo
authorSamir Benmendil <me@rmz.io>
Mon, 3 Oct 2016 22:41:41 +0000 (23:41 +0100)
committerSamir Benmendil <me@rmz.io>
Mon, 3 Oct 2016 22:41:41 +0000 (23:41 +0100)
zsh/lib/chpwd.zsh [new file with mode: 0644]

diff --git a/zsh/lib/chpwd.zsh b/zsh/lib/chpwd.zsh
new file mode 100644 (file)
index 0000000..1763cd5
--- /dev/null
@@ -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)