6bd95ddbdcb0ee51ec41e28bc07c6d64e96670ba
- Author
- Marc Cornellà <marc.cornella@live.com>
- Committer
- GitHub <noreply@github.com>
- Date
Message
add plugin: git-auto-fetch (#5477)
Diff
1diff --git a/plugins/git-auto-fetch/README.md b/plugins/git-auto-fetch/README.md
2new file mode 100644
3index 0000000000000000000000000000000000000000..04f1c94459074d3fe8f2b67f9e147457336be2c6
4--- /dev/null
5+++ b/plugins/git-auto-fetch/README.md
6@@ -0,0 +1,29 @@
7+# Git auto fetch
8+
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+```shell
14+plugins=(... git-auto-fetch)
15+```
16+
17+Every time you launch a command in your shell all remotes will be fetched in background.
18+By default autofetch will be triggered only if last fetch was done at least 60 seconds ago.
19+You can change fetch interval in your .zshrc:
20+```
21+GIT_AUTO_FETCH_INTERVAL=1200 #in seconds
22+```
23+Log of ```git fetch --all``` will be saved into .git/FETCH_LOG
24+
25+
26+####Toggle auto fetch per folder
27+If you are using mobile connection or for any other reason you can disable git-auto-fetch for any folder:
28+
29+```shell
30+$ cd to/your/project
31+$ git-auto-fetch
32+disabled
33+$ git-auto-fetch
34+enabled
35+```
36diff --git a/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh b/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh
37new file mode 100644
38index 0000000000000000000000000000000000000000..1d20bc04bc9f772ee3c15c870fd5ff2e0dc42339
39--- /dev/null
40+++ b/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh
41@@ -0,0 +1,27 @@
42+GIT_AUTO_FETCH_INTERVAL=${GIT_AUTO_FETCH_INTERVAL:=60}
43+
44+function git-fetch-all {
45+ (`git rev-parse --is-inside-work-tree 2>/dev/null` &&
46+ dir=`git rev-parse --git-dir` &&
47+ [[ ! -f $dir/NO_AUTO_FETCH ]] &&
48+ (( `date +%s` - `date -r $dir/FETCH_LOG +%s 2>/dev/null || echo 0` > $GIT_AUTO_FETCH_INTERVAL )) &&
49+ git fetch --all &>! $dir/FETCH_LOG &)
50+}
51+
52+function git-auto-fetch {
53+ `git rev-parse --is-inside-work-tree 2>/dev/null` || return
54+ guard="`git rev-parse --git-dir`/NO_AUTO_FETCH"
55+
56+ (rm $guard 2>/dev/null &&
57+ echo "${fg_bold[green]}enabled${reset_color}") ||
58+ (touch $guard &&
59+ echo "${fg_bold[red]}disabled${reset_color}")
60+}
61+
62+eval "override-git-auto-fetch-$(declare -f zle-line-init)"
63+
64+function zle-line-init () {
65+ git-fetch-all
66+ override-git-auto-fetch-zle-line-init
67+}
68+zle -N zle-line-init