Add bash autofetch feature

This commit is contained in:
Talia 2020-01-07 10:38:05 +01:00
parent e0c4c5942b
commit 6a94b6d2ec
1 changed files with 17 additions and 2 deletions

19
bashrc
View File

@ -26,10 +26,25 @@ stty -ixon
# Enable Vi editing mode # Enable Vi editing mode
set -o vi set -o vi
git__fetch() {
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
touch $1/.git/FETCH_HEAD
nohup git fetch > /dev/null 2>&1
fi
}
git__prompt () { git__prompt () {
git rev-parse --show-toplevel > /dev/null 2>&1 top=$(git rev-parse --show-toplevel 2>/dev/null)
if [ $? = 0 ] if [ -n "$top" ]
then then
if [ $BASH_AUTOFETCH ]; then
git__fetch $top
fi
echo -ne ' \033[00;33mδ' echo -ne ' \033[00;33mδ'
status=`git status --short 2>/dev/null` status=`git status --short 2>/dev/null`
branch=`git branch | grep -Po '(?<=\* )[[:alnum:]_-]*'` branch=`git branch | grep -Po '(?<=\* )[[:alnum:]_-]*'`