Diff
1diff --git a/plugins/git-auto-fetch/README.md b/plugins/git-auto-fetch/README.md
2index 7f5eac49d8257d16a5d7c61df4239930da9b81a1..04f1c94459074d3fe8f2b67f9e147457336be2c6 100644
3--- a/plugins/git-auto-fetch/README.md
4+++ b/plugins/git-auto-fetch/README.md
5@@ -1,6 +1,6 @@
6 # Git auto fetch
7
8-Automatically fetches all changes from all remotes every time you cd into yout git-initialized project.
9+Automatically fetches all changes from all remotes while you are working in git-initialized directory.
10
11 ####Usage
12 Add ```git-auto-fetch``` to the plugins array in your zshrc file:
13@@ -8,7 +8,14 @@ Add ```git-auto-fetch``` to the plugins array in your zshrc file:
14 plugins=(... git-auto-fetch)
15 ```
16
17-Every time you change directory to your git project all remotes will be fetched in background. Log of ```git fetch --all``` will be saved into .git/FETCH_LOG
18+Every time you launch a command in your shell all remotes will be fetched in background.
19+By default autofetch will be triggered only if last fetch was done at least 60 seconds ago.
20+You can change fetch interval in your .zshrc:
21+```
22+GIT_AUTO_FETCH_INTERVAL=1200 #in seconds
23+```
24+Log of ```git fetch --all``` will be saved into .git/FETCH_LOG
25+
26
27 ####Toggle auto fetch per folder
28 If you are using mobile connection or for any other reason you can disable git-auto-fetch for any folder:
29diff --git a/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh b/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh
30index 949709e4c065efd560dbeec68cf8141a6c39a322..e9946ef3fa78e9f0d2cf99e118fa406b3c207beb 100644
31--- a/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh
32+++ b/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh
33@@ -1,7 +1,10 @@
34-function git-fetch-on-chpwd {
35+GIT_AUTO_FETCH_INTERVAL=${GIT_AUTO_FETCH_INTERVAL:=60}
36+
37+function git-fetch-all {
38 (`git rev-parse --is-inside-work-tree 2>/dev/null` &&
39 dir=`git rev-parse --git-dir` &&
40 [[ ! -f $dir/NO_AUTO_FETCH ]] &&
41+ (( `date +%s` - `date -r $dir/FETCH_LOG +%s` > $GIT_AUTO_FETCH_INTERVAL )) &&
42 git fetch --all &>! $dir/FETCH_LOG &)
43 }
44
45@@ -15,6 +18,15 @@ function git-auto-fetch {
46 echo "${fg_bold[red]}disabled${reset_color}")
47 }
48
49-chpwd_functions+=(git-fetch-on-chpwd)
50-git-fetch-on-chpwd
51-unset git-fetch-on-chpwd
52+eval "original-$(declare -f zle-line-init)"
53+
54+function zle-line-init () {
55+ git-fetch-all
56+ original-zle-line-init
57+}
58+zle -N zle-line-init
59+
60+# chpwd_functions+=(git-fetch-on-chpwd)
61+# git-fetch-on-chpwd
62+unset git-auto-fetch
63+unset original-zle-line-init