Improve bash autofetch feature

Added BASH_AUTOFETCH_TIMEOUT option and actually sent fetching to the
background.
This commit is contained in:
Talia 2020-01-07 10:51:55 +01:00
parent 6a94b6d2ec
commit 7a6a5c5ed2

9
bashrc
View file

@ -27,14 +27,19 @@ stty -ixon
set -o vi set -o vi
git__fetch() { git__fetch() {
if [ -n "$BASH_AUTOFETCH_TIMEOUT" ]; then
timeout=$BASH_AUTOFETCH_TIMEOUT
else
timeout=60
fi
if [ -f $1/.git/FETCH_HEAD ]; then if [ -f $1/.git/FETCH_HEAD ]; then
diff=$(($(date +%s) - $(stat -c %Y $1/.git/FETCH_HEAD))) diff=$(($(date +%s) - $(stat -c %Y $1/.git/FETCH_HEAD)))
else else
diff=9999 diff=9999
fi fi
if [ $diff -gt 60 ]; then if [ $diff -gt $timeout ]; then
touch $1/.git/FETCH_HEAD touch $1/.git/FETCH_HEAD
nohup git fetch > /dev/null 2>&1 nohup git fetch > /dev/null 2>&1 &
fi fi
} }