Last active
February 17, 2024 16:34
-
-
Save luckman212/095fdb8544eef1aad8bda5d8d4dbc8d0 to your computer and use it in GitHub Desktop.
json-diff using jd, for diffing Syncthing file debug outputs: https://docs.syncthing.net/rest/db-file-get.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
case $1 in | |
-h|--help|'') echo "${0##*/} [files-or-dir]"; exit;; | |
esac | |
#requires jd, jq | |
for f in jd jq; do | |
if ! hash $f &>/dev/null; then brew install --quiet $f; fi | |
done | |
declare -A FARR | |
c=0 | |
if [[ -d $1 ]]; then | |
FPATH=$(realpath "$1") | |
while IFS= read -r FNAME; do | |
FARR[$c]="$FNAME" | |
(( c++ )) | |
done < <(find -s "$FPATH" -type f -name "*.json") | |
else | |
for FNAME in "$@"; do | |
FARR[$c]="$FNAME" | |
(( c++ )) | |
done | |
fi | |
ARRSIZE=${#FARR[@]} | |
if (( ARRSIZE == 0 )); then | |
echo 1>&2 "no files to process" | |
exit | |
fi | |
for (( n=1; n<ARRSIZE; n++ )); do | |
(( p = n - 1 )) | |
clear | |
echo "${FG}comparing ${FARR[$p]} <==> ${FARR[$n]}${FN}" | |
jd -f jd -color "${FARR[$p]}" "${FARR[$n]}" | |
echo | |
echo "${FL}.global.platform.darwin ONLY diff:${FN}" | |
jq -r <"${FARR[$p]}" '.global.platform.darwin' >/tmp/p | |
jq -r <"${FARR[$n]}" '.global.platform.darwin' >/tmp/n | |
if jd -f jd -color /tmp/p /tmp/n; then | |
echo "${FG}** no diff **${FN}" | |
fi | |
echo | |
left=$(( ARRSIZE - n - 1 )) | |
(( left > 0 )) && read -r -p "press <ENTER> to continue or ⌃c to ABORT ($left left)" | |
done | |
rm /tmp/p /tmp/n 2>/dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
syncthing/syncthing#9371 (comment)