From a1200f5bccd7c0ebe327ccbc554d56247136d48c Mon Sep 17 00:00:00 2001 From: slavaGanzin Date: Thu, 29 Sep 2016 19:05:49 +0300 Subject: [PATCH 01/11] git auto fetch on change directory --- plugins/git-auto-fetch/git-auto-fetch.plugin.zsh | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 plugins/git-auto-fetch/git-auto-fetch.plugin.zsh diff --git a/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh b/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh new file mode 100644 index 000000000..841f47baf --- /dev/null +++ b/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh @@ -0,0 +1,5 @@ +function git_fetch_on_chpwd { + ([[ -d .git ]] && git fetch --all >! ./.git/FETCH_LOG &) +} +chpwd_functions=(${chpwd_functions[@]} "git_fetch_on_chpwd") +unset git_fetch_on_cpwd From 1427fbffef68d5796c8296ba105f325598b809f8 Mon Sep 17 00:00:00 2001 From: slavaGanzin Date: Thu, 29 Sep 2016 22:14:04 +0300 Subject: [PATCH 02/11] redirect output --- plugins/git-auto-fetch/git-auto-fetch.plugin.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh b/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh index 841f47baf..cbf6984a0 100644 --- a/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh +++ b/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh @@ -1,5 +1,5 @@ function git_fetch_on_chpwd { - ([[ -d .git ]] && git fetch --all >! ./.git/FETCH_LOG &) + ([[ -d .git ]] && git fetch --all &>! ./.git/FETCH_LOG &) } -chpwd_functions=(${chpwd_functions[@]} "git_fetch_on_chpwd") -unset git_fetch_on_cpwd +chpwd_functions+=(git_fetch_on_chpwd) +git_fetch_on_chpwd From 25fcf0c265c682f092ce49a6849e5e09b38dffa9 Mon Sep 17 00:00:00 2001 From: slavaGanzin Date: Tue, 4 Oct 2016 21:26:19 +0300 Subject: [PATCH 03/11] git-auto-fetch: README.md --- plugins/git-auto-fetch/README.md | 22 +++++++++++++++++++ .../git-auto-fetch/git-auto-fetch.plugin.zsh | 12 +++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 plugins/git-auto-fetch/README.md diff --git a/plugins/git-auto-fetch/README.md b/plugins/git-auto-fetch/README.md new file mode 100644 index 000000000..7f5eac49d --- /dev/null +++ b/plugins/git-auto-fetch/README.md @@ -0,0 +1,22 @@ +# Git auto fetch + +Automatically fetches all changes from all remotes every time you cd into yout git-initialized project. + +####Usage +Add ```git-auto-fetch``` to the plugins array in your zshrc file: +```shell +plugins=(... git-auto-fetch) +``` + +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 + +####Toggle auto fetch per folder +If you are using mobile connection or for any other reason you can disable git-auto-fetch for any folder: + +```shell +$ cd to/your/project +$ git-auto-fetch +disabled +$ git-auto-fetch +enabled +``` diff --git a/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh b/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh index cbf6984a0..87535b251 100644 --- a/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh +++ b/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh @@ -1,5 +1,15 @@ function git_fetch_on_chpwd { - ([[ -d .git ]] && git fetch --all &>! ./.git/FETCH_LOG &) + ([[ -d .git ]] && [[ ! -f ".git/NO_AUTO_FETCH" ]] && git fetch --all &>! .git/FETCH_LOG &) +} + +function git-auto-fetch { + [[ ! -d .git ]] && return + if [[ -f ".git/NO_AUTO_FETCH" ]]; then + rm ".git/NO_AUTO_FETCH" && echo "disabled" + else + touch ".git/NO_AUTO_FETCH" && echo "enabled" + fi } chpwd_functions+=(git_fetch_on_chpwd) git_fetch_on_chpwd +unset git_fetch_on_chpwd From ac7dcdb21cfb57180c7d8007d95232ee62086997 Mon Sep 17 00:00:00 2001 From: slavaGanzin Date: Thu, 6 Oct 2016 16:55:21 +0300 Subject: [PATCH 04/11] add colors --- plugins/git-auto-fetch/git-auto-fetch.plugin.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh b/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh index 87535b251..0bcefa931 100644 --- a/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh +++ b/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh @@ -5,9 +5,9 @@ function git_fetch_on_chpwd { function git-auto-fetch { [[ ! -d .git ]] && return if [[ -f ".git/NO_AUTO_FETCH" ]]; then - rm ".git/NO_AUTO_FETCH" && echo "disabled" + rm ".git/NO_AUTO_FETCH" && echo "${fg_bold[red]}disabled${reset_color}" else - touch ".git/NO_AUTO_FETCH" && echo "enabled" + touch ".git/NO_AUTO_FETCH" && echo "${fg_bold[green]}enabled${reset_color}" fi } chpwd_functions+=(git_fetch_on_chpwd) From 028fdf2e9948fa720599a63cd36124eff95cb6fc Mon Sep 17 00:00:00 2001 From: slavaGanzin Date: Mon, 10 Oct 2016 22:33:09 +0300 Subject: [PATCH 05/11] add coloring --- .../git-auto-fetch/git-auto-fetch.plugin.zsh | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh b/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh index 0bcefa931..949709e4c 100644 --- a/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh +++ b/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh @@ -1,15 +1,20 @@ -function git_fetch_on_chpwd { - ([[ -d .git ]] && [[ ! -f ".git/NO_AUTO_FETCH" ]] && git fetch --all &>! .git/FETCH_LOG &) +function git-fetch-on-chpwd { + (`git rev-parse --is-inside-work-tree 2>/dev/null` && + dir=`git rev-parse --git-dir` && + [[ ! -f $dir/NO_AUTO_FETCH ]] && + git fetch --all &>! $dir/FETCH_LOG &) } function git-auto-fetch { - [[ ! -d .git ]] && return - if [[ -f ".git/NO_AUTO_FETCH" ]]; then - rm ".git/NO_AUTO_FETCH" && echo "${fg_bold[red]}disabled${reset_color}" - else - touch ".git/NO_AUTO_FETCH" && echo "${fg_bold[green]}enabled${reset_color}" - fi + `git rev-parse --is-inside-work-tree 2>/dev/null` || return + guard="`git rev-parse --git-dir`/NO_AUTO_FETCH" + + (rm $guard 2>/dev/null && + echo "${fg_bold[green]}enabled${reset_color}") || + (touch $guard && + echo "${fg_bold[red]}disabled${reset_color}") } -chpwd_functions+=(git_fetch_on_chpwd) -git_fetch_on_chpwd -unset git_fetch_on_chpwd + +chpwd_functions+=(git-fetch-on-chpwd) +git-fetch-on-chpwd +unset git-fetch-on-chpwd From 9f2977f3eb969a8b026d1fc84394bef0d1a9ee78 Mon Sep 17 00:00:00 2001 From: slavaGanzin Date: Mon, 10 Oct 2016 22:30:47 +0300 Subject: [PATCH 06/11] reimplement --- $ | 0 disabled | 0 echo | 0 plugins/zsh-syntax-highlighting | 1 + 4 files changed, 1 insertion(+) create mode 100644 $ create mode 100644 disabled create mode 100644 echo create mode 160000 plugins/zsh-syntax-highlighting diff --git a/$ b/$ new file mode 100644 index 000000000..e69de29bb diff --git a/disabled b/disabled new file mode 100644 index 000000000..e69de29bb diff --git a/echo b/echo new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/zsh-syntax-highlighting b/plugins/zsh-syntax-highlighting new file mode 160000 index 000000000..094329eb1 --- /dev/null +++ b/plugins/zsh-syntax-highlighting @@ -0,0 +1 @@ +Subproject commit 094329eb145e00b810e65415ed4b9ad58aa7c34a From dbee3dd9c69c8d2e3299f2f7e7c68fabd06e33c5 Mon Sep 17 00:00:00 2001 From: slavaGanzin Date: Wed, 26 Oct 2016 23:47:51 +0300 Subject: [PATCH 07/11] 1. autofetch on zle-line-init 2. GIT_AUTO_FETCH_INTERVAL --- plugins/git-auto-fetch/README.md | 11 ++++++++-- .../git-auto-fetch/git-auto-fetch.plugin.zsh | 20 +++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/plugins/git-auto-fetch/README.md b/plugins/git-auto-fetch/README.md index 7f5eac49d..04f1c9445 100644 --- a/plugins/git-auto-fetch/README.md +++ b/plugins/git-auto-fetch/README.md @@ -1,6 +1,6 @@ # Git auto fetch -Automatically fetches all changes from all remotes every time you cd into yout git-initialized project. +Automatically fetches all changes from all remotes while you are working in git-initialized directory. ####Usage Add ```git-auto-fetch``` to the plugins array in your zshrc file: @@ -8,7 +8,14 @@ Add ```git-auto-fetch``` to the plugins array in your zshrc file: plugins=(... git-auto-fetch) ``` -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 +Every time you launch a command in your shell all remotes will be fetched in background. +By default autofetch will be triggered only if last fetch was done at least 60 seconds ago. +You can change fetch interval in your .zshrc: +``` +GIT_AUTO_FETCH_INTERVAL=1200 #in seconds +``` +Log of ```git fetch --all``` will be saved into .git/FETCH_LOG + ####Toggle auto fetch per folder If you are using mobile connection or for any other reason you can disable git-auto-fetch for any folder: diff --git a/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh b/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh index 949709e4c..e9946ef3f 100644 --- a/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh +++ b/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh @@ -1,7 +1,10 @@ -function git-fetch-on-chpwd { +GIT_AUTO_FETCH_INTERVAL=${GIT_AUTO_FETCH_INTERVAL:=60} + +function git-fetch-all { (`git rev-parse --is-inside-work-tree 2>/dev/null` && dir=`git rev-parse --git-dir` && [[ ! -f $dir/NO_AUTO_FETCH ]] && + (( `date +%s` - `date -r $dir/FETCH_LOG +%s` > $GIT_AUTO_FETCH_INTERVAL )) && git fetch --all &>! $dir/FETCH_LOG &) } @@ -15,6 +18,15 @@ function git-auto-fetch { echo "${fg_bold[red]}disabled${reset_color}") } -chpwd_functions+=(git-fetch-on-chpwd) -git-fetch-on-chpwd -unset git-fetch-on-chpwd +eval "original-$(declare -f zle-line-init)" + +function zle-line-init () { + git-fetch-all + original-zle-line-init +} +zle -N zle-line-init + +# chpwd_functions+=(git-fetch-on-chpwd) +# git-fetch-on-chpwd +unset git-auto-fetch +unset original-zle-line-init From 41ad705f93bfb1cd75e4c69d1cc936107556b827 Mon Sep 17 00:00:00 2001 From: slavaGanzin Date: Thu, 27 Oct 2016 00:03:31 +0300 Subject: [PATCH 08/11] cut comments --- plugins/git-auto-fetch/git-auto-fetch.plugin.zsh | 5 ----- 1 file changed, 5 deletions(-) diff --git a/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh b/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh index e9946ef3f..7dbd63fe1 100644 --- a/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh +++ b/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh @@ -25,8 +25,3 @@ function zle-line-init () { original-zle-line-init } zle -N zle-line-init - -# chpwd_functions+=(git-fetch-on-chpwd) -# git-fetch-on-chpwd -unset git-auto-fetch -unset original-zle-line-init From 41e65c0872fc29a604aea007aeba011334a6ac4c Mon Sep 17 00:00:00 2001 From: slavaGanzin Date: Thu, 17 Nov 2016 15:30:27 +0200 Subject: [PATCH 09/11] remove trash --- $ | 0 disabled | 0 echo | 0 plugins/zsh-syntax-highlighting | 1 - 4 files changed, 1 deletion(-) delete mode 100644 $ delete mode 100644 disabled delete mode 100644 echo delete mode 160000 plugins/zsh-syntax-highlighting diff --git a/$ b/$ deleted file mode 100644 index e69de29bb..000000000 diff --git a/disabled b/disabled deleted file mode 100644 index e69de29bb..000000000 diff --git a/echo b/echo deleted file mode 100644 index e69de29bb..000000000 diff --git a/plugins/zsh-syntax-highlighting b/plugins/zsh-syntax-highlighting deleted file mode 160000 index 094329eb1..000000000 --- a/plugins/zsh-syntax-highlighting +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 094329eb145e00b810e65415ed4b9ad58aa7c34a From a90527b46d67e70f92258849b265b6bfd5e910e0 Mon Sep 17 00:00:00 2001 From: slavaGanzin Date: Thu, 17 Nov 2016 15:51:40 +0200 Subject: [PATCH 10/11] fix FETCH_LOG bug --- plugins/git-auto-fetch/git-auto-fetch.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh b/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh index 7dbd63fe1..03fa911e7 100644 --- a/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh +++ b/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh @@ -4,7 +4,7 @@ function git-fetch-all { (`git rev-parse --is-inside-work-tree 2>/dev/null` && dir=`git rev-parse --git-dir` && [[ ! -f $dir/NO_AUTO_FETCH ]] && - (( `date +%s` - `date -r $dir/FETCH_LOG +%s` > $GIT_AUTO_FETCH_INTERVAL )) && + (( `date +%s` - `date -r $dir/FETCH_LOG +%s 2>/dev/null || echo 0` > $GIT_AUTO_FETCH_INTERVAL )) && git fetch --all &>! $dir/FETCH_LOG &) } From d2dfa69419845daebcfd20fed3253ae06faa2876 Mon Sep 17 00:00:00 2001 From: slavaGanzin Date: Tue, 7 Feb 2017 15:44:12 +0200 Subject: [PATCH 11/11] change name of overriden zle-line-init --- plugins/git-auto-fetch/git-auto-fetch.plugin.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh b/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh index 03fa911e7..1d20bc04b 100644 --- a/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh +++ b/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh @@ -18,10 +18,10 @@ function git-auto-fetch { echo "${fg_bold[red]}disabled${reset_color}") } -eval "original-$(declare -f zle-line-init)" +eval "override-git-auto-fetch-$(declare -f zle-line-init)" function zle-line-init () { git-fetch-all - original-zle-line-init + override-git-auto-fetch-zle-line-init } zle -N zle-line-init