From 3a5738240a298ffaf4f79e8b8d9dac7d80a361b9 Mon Sep 17 00:00:00 2001 From: earthlng Date: Mon, 26 Nov 2018 18:25:54 +0000 Subject: [PATCH] Update updater.sh --- updater.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/updater.sh b/updater.sh index 5eca133..45bf66d 100755 --- a/updater.sh +++ b/updater.sh @@ -2,7 +2,7 @@ ## ghacks-user.js updater for macOS and Linux -## version: 2.1 +## version: 2.2 ## Author: Pat Johnson (@overdodactyl) ## Additional contributors: @earthlng, @ema-pe @@ -317,14 +317,20 @@ update_userjs () { remove_comments user.js $current_nocomments diffname="userjs_diffs/diff_$(date +"%Y-%m-%d_%H%M").txt" - diff=$(diff -w -B -U 0 $past_nocomments $current_nocomments) + diff=$(sdiff -s -w 500 $past_nocomments $current_nocomments) if [ ! -z "$diff" ]; then - echo "$diff" > "$diffname" + local leasttabs=999999 + while read line; do + ntabs=$(echo "$line" | tr -c -d "\t" | wc -c) + # somehow lines starting with TAB are counted as 1 so we need to catch that + if [ $ntabs -gt 1 ] && [ $ntabs -lt $leasttabs ]; then leasttabs=$ntabs; fi + done <<< "$diff" + # strip leasttabs-1 number of TABS once per line + sed -E 's/\t{'$((leasttabs-1))'}//1' <<< "$diff" > "$diffname" echo -e "Status: ${GREEN}A diff file was created:${NC} ${PWD}/${diffname}" else echo -e "Warning: ${ORANGE}Your new user.js file appears to be identical. No diff file was created.${NC}" fi - rm $past_nocomments $current_nocomments $pastuserjs fi