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
git__fetch() {
if [ -n "$BASH_AUTOFETCH_TIMEOUT" ]; then
timeout=$BASH_AUTOFETCH_TIMEOUT
else
timeout=60
fi
if [ -f $1/.git/FETCH_HEAD ]; then
diff=$(($(date +%s) - $(stat -c %Y $1/.git/FETCH_HEAD)))
else
diff=9999
fi
if [ $diff -gt 60 ]; then
if [ $diff -gt $timeout ]; then
touch $1/.git/FETCH_HEAD
nohup git fetch > /dev/null 2>&1
nohup git fetch > /dev/null 2>&1 &
fi
}