From 690975594fa4003011dedf26d2356d47bae4942e Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Fri, 23 Apr 2021 09:13:26 -0300 Subject: Fix: git-config-save: adds --sometimes flag --- git-config-save | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/git-config-save b/git-config-save index 5c040e4..dad19ef 100755 --- a/git-config-save +++ b/git-config-save @@ -51,6 +51,9 @@ BASENAME="`basename $0`" BASE="$HOME/.config/gitconfigs" DATE="`date +%Y%m%d%I%M%S`" FILENAME="gitconfig.saved" +OPTION="$1" +COUNTER="$BASE/counter" +SOMETIMES="20" # Ensure we have a base and that is minimally safe mkdir -p $BASE @@ -125,6 +128,24 @@ function git_config_restore { echo "Backup saved at $pwd/.git/config.$DATE" } +# Check option +if [ ! -z "$OPTION" ] && [ "$OPTION" == "--sometimes" ]; then + if [ ! -e "$COUNTER" ]; then + echo 0 > $COUNTER + fi + + COUNT="`cat $COUNTER`" + + if (($COUNT >= $SOMETIMES)); then + echo 0 > $COUNTER + else + let COUNT++ + echo $COUNT > $COUNTER + echo "Running only sometimes. This is run ${COUNT} of ${SOMETIMES}, skipping." + exit 1 + fi +fi + # Process everything we can find find -type d -name .git | while read repo; do # Get absolute folder -- cgit v1.2.3