diff --git a/rc b/rc index 45f8b01..04c5ad2 100755 --- a/rc +++ b/rc @@ -69,20 +69,23 @@ unset -f _check_ncsv } # Update self weekly, # if folder writable, if repository, if an interactive terminal, if not updated the last week -[[ -w "$TOOLSPATH" ]] || return -[[ -w "$TOOLSPATH"/.hg ]] || return -[[ -t 0 ]] || return -[[ -t 1 ]] || return -[[ -t 2 ]] || return +TOOLS_TO_UPDATE=1 +[[ -w "$TOOLSPATH" ]] || TOOLS_TO_UPDATE=0 +[[ -w "$TOOLSPATH"/.hg ]] || TOOLS_TO_UPDATE=0 +[[ -t 0 ]] || TOOLS_TO_UPDATE=0 +[[ -t 1 ]] || TOOLS_TO_UPDATE=0 +[[ -t 2 ]] || TOOLS_TO_UPDATE=0 [[ -f "$TOOLSPATH"/.lastupdate ]] || touch -t 0101010101 "$TOOLSPATH"/.lastupdate 2> /dev/null -[[ -w "$TOOLSPATH"/.lastupdate ]] || return +[[ -w "$TOOLSPATH"/.lastupdate ]] || TOOLS_TO_UPDATE=0 -_change_hg_repo +if [ $TOOLS_TO_UPDATE -eq 1 ]; then + _change_hg_repo + TOOLS_LASTUPDATE=$(( $( date +%s ) - $( stat -c %Y "$TOOLSPATH"/.lastupdate ) )) + [[ "$TOOLS_LASTUPDATE" -gt 604800 ]] && _self_update + unset TOOLS_LASTUPDATE +fi +unset TOOLS_TO_UPDATE +unset -f _self_update unset -f _change_hg_repo -TOOLS_LASTUPDATE=$(( $( date +%s ) - $( stat -c %Y "$TOOLSPATH"/.lastupdate ) )) -[[ "$TOOLS_LASTUPDATE" -gt 604800 ]] && _self_update -unset TOOLS_LASTUPDATE -unset -f _self_update -