bin: make dif commands flexible
This commit is contained in:
parent
f5d8c4094c
commit
867f019928
|
@ -1,19 +1,31 @@
|
||||||
#!/bin/bash -ex
|
#!/bin/bash -e
|
||||||
# interactive diff with pagination and nice coloring
|
# interactive diff with pagination and nice coloring
|
||||||
# TODO diff sqlite repos with sqldiff
|
declare -a files
|
||||||
mime="$(file --brief --mime "$1" "$2")"
|
while test $# -gt 0
|
||||||
|
do test "$1" == "--" && shift &&
|
||||||
|
command="$@" && break
|
||||||
|
files+=("$1")
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
{
|
||||||
|
if ! test "$command"; then
|
||||||
|
mime="$(file --brief --mime "${files[@]}")"
|
||||||
case "$mime" in
|
case "$mime" in
|
||||||
(*audio*)
|
(*audio*) command="ffprobe -loglevel warning -print_format default=noprint_wrappers=1 -show_format -pretty";;
|
||||||
ff() { ffprobe -loglevel warning -print_format default=noprint_wrappers=1 -show_format -pretty "$@"; }
|
(image/*) command="exiftool";;
|
||||||
$(test $(tput cols) -gt 120 && echo "diff --color=always --side-by-side" || echo "diff-color") \
|
(*sqlite*) sqldiff --summary "${files[@]}" | grep -v '0 changes, 0 inserts, 0 deletes';; # TODO syntax highlighting for INSERT/UPDATE/DELETE
|
||||||
--report-identical-files --label="$1" --label="$2" <(ff "$1") <(ff "$2")
|
|
||||||
;;
|
|
||||||
(*sqlite*) sqldiff "$@" ;;
|
|
||||||
(text/*)
|
(text/*)
|
||||||
# Use wiked-diff only for text <10MB
|
# Use wiked-diff only for text <10MB
|
||||||
if test 10000000 -gt "$(stat --format=%s *.geojson | paste -s -d'+' | bc)"
|
if test 10000000 -gt "$(stat --format=%s *.geojson | paste -s -d'+' | bc)"
|
||||||
then wiked-diff "$@"
|
then wiked-diff "${files[@]}"
|
||||||
else diff --color=always --unified=1 --report-identical-files "$@"
|
else diff --color=always --unified=1 --report-identical-files "${files[@]}"
|
||||||
fi;;
|
fi;;
|
||||||
(*) diff-color --report-identical-files "$@";;
|
(*) diff-color --report-identical-files "${files[@]}";;
|
||||||
esac | less --RAW-CONTROL-CHARS --quit-on-intr --quit-if-one-screen
|
esac
|
||||||
|
fi
|
||||||
|
if test "$command"; then
|
||||||
|
echo "Generated through $command"
|
||||||
|
$(test $(tput cols) -gt 120 && echo "diff --color=always --side-by-side" || echo "diff-color") \
|
||||||
|
--report-identical-files --label="${files[0]}" --label="${files[1]}" <($command "${files[0]}") <($command "${files[1]}")
|
||||||
|
fi
|
||||||
|
} | less --RAW-CONTROL-CHARS --quit-on-intr --quit-if-one-screen
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#!/bin/sh -e
|
#!/bin/sh
|
||||||
# Delete files under current or given path which exist elsewhere as listed in the locate database
|
# Delete files under current or given path which exist elsewhere as listed in the locate database
|
||||||
# Matches first by name, then by checksum (currently inefficiently via md5)
|
# Matches first by name, then by checksum (currently inefficiently via md5)
|
||||||
case $1 in ([0-9]|[0-9][0-9]) threshold=$1; shift;; esac
|
case $1 in ([0-9]|[0-9][0-9]) threshold=$1; shift;; esac
|
||||||
find "$@" -size +${threshold:-50}M -type f -exec sh -c "IFS=$'\n'"'
|
find "$@" -size +${threshold:-50}M -type f -exec sh -c "IFS=$'\n'"'
|
||||||
filepath="{}"
|
filepath="{}"
|
||||||
target="$(basename "$filepath" | synct-unarchive)"
|
target="$(synct-unarchive "$filepath")"
|
||||||
highlight "$filepath"
|
highlight "$filepath"
|
||||||
for existing in $(locate -b "$target")
|
for existing in $(locate -b "$target")
|
||||||
do test "$(realpath "$target")" != "$(realpath "$existing")" -a -f "$existing" && test "$(md5sum "$existing" | cut -d\ -f1)" = "$(md5sum "$filepath" | cut -d\ -f1)" && echo "Found duplicate at $existing" && rm -vi "$filepath" && break
|
do test "$(realpath "$target")" != "$(realpath "$existing")" -a -f "$existing" && test "$(md5sum "$existing" | cut -d\ -f1)" = "$(md5sum "$filepath" | cut -d\ -f1)" && echo "Found duplicate at $existing" && rm -vi "$filepath" && break
|
||||||
|
|
Loading…
Reference in New Issue