the_earnest/dotfiles
moved some scripts from ~/bin into dotfiles/scripts
Commit 6081e0815401 · The Earnest · 2026-11-24 16:05 +0000
Comments
No comments yet.
Diff
diff --git a/scripts/downscale_large_jpegs.sh b/scripts/downscale_large_jpegs.sh
new file mode 100755
--- /dev/null
+++ b/scripts/downscale_large_jpegs.sh
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+function downscale() {
+
+ total_before=0
+ total_after=0
+ total_savings=0
+
+ while read f
+ do
+ before=$(stat -c "%s" "$f")
+ (( total_before+=before ))
+
+ magick mogrify -define preserve-timestamp=true -scale 50% "$f"
+
+ after=$(stat -c "%s" "$f")
+ (( total_after+=after ))
+ (( savings=before-after ))
+ (( total_savings+=savings ))
+
+ percent=$(echo "scale=2;100*$savings/$before" | bc)
+ #printf "%s before:%d after:%d saved:%d (%.0f%%)\n" "$f" "$before" "$after" "$savings" "$percent"
+ printf "%s - saved %.0f%%\n" "$f" "$percent"
+
+ done
+
+ # report total savings
+ percent=$(echo "scale=2;100*$total_savings/$total_before" | bc)
+ printf "\ntotal size reduction: from %d to %d (%.0f%%), for %d bytes\n" $total_before $total_after $percent $total_savings
+}
+
+INPUTFILE=large_jpegs.txt
+if [[ ! -e "$INPUTFILE" ]]
+then
+ echo "error: input file \"$INPUTFILE\" not found in this directory"
+ exit
+fi
+
+cat $INPUTFILE | downscale
+
+if [[ $? -eq 0 ]]
+then
+ echo removing $INPUTFILE
+ rm $INPUTFILE
+else
+ echo "function did not return zero; presumable error; not removing $INPUTFILE"
+fi
diff --git a/scripts/find_large_jpegs.sh b/scripts/find_large_jpegs.sh
new file mode 100755
--- /dev/null
+++ b/scripts/find_large_jpegs.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+
+if [[ $# -ne 1 ]]
+then
+ echo "error: must pass 1 argument (filename fragment)"
+ exit 1
+fi
+
+echo -n Running find...
+TMP_MATCHED="$TMPDIR/tmp_matched"
+find -type f -iname "*${1}*\\.jpg" >"$TMP_MATCHED"
+wc -l "$TMP_MATCHED"
+
+echo Running identify...
+TMP_IDENTIFIED="$TMPDIR/tmp_identified"
+xargs -d'\n' -r -a "$TMP_MATCHED" identify >"$TMP_IDENTIFIED"
+
+echo Running grep...
+TMP_TOO_LARGE="$TMPDIR/tmp_too_large"
+grep -E "\
+(3072x3072)|\
+(4096x3072)|\
+(4096x2304)|\
+(4096x1844)|\
+(3264x2448)|\
+(4000x3000)" "$TMP_IDENTIFIED" >"$TMP_TOO_LARGE"
+
+if [[ -s "$TMP_TOO_LARGE" ]]
+then
+ echo Running sed...
+ sed -e 's/ JPEG .*//' "$TMP_TOO_LARGE" >large_jpegs.txt
+ wc -l large_jpegs.txt
+else
+ echo "No large JPGs found."
+fi
+
+rm "$TMP_MATCHED" "$TMP_IDENTIFIED" "$TMP_TOO_LARGE"
+
diff --git a/scripts/findandedit b/scripts/findandedit
new file mode 100755
--- /dev/null
+++ b/scripts/findandedit
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+THIS=$(basename $0)
+
+if [[ "$1" == "-v" ]]; then
+ VERBOSE=verbose
+ shift
+fi
+
+FINDCMD="find "
+
+# exclusions
+FINDCMD+="-type d \( "
+FINDCMD+="-path '*/.hg' -o "
+FINDCMD+="-path '*/.git' "
+FINDCMD+=" \) -prune -o "
+
+# search for exact match
+FINDCMD+="-name '$1' "
+FINDCMD+="-exec vim {} +"
+
+[[ -n $VERBOSE ]] && echo $THIS: FINDCMD=$FINDCMD
+
+eval $FINDCMD
diff --git a/scripts/remove_paired_mobis b/scripts/remove_paired_mobis
new file mode 100755
--- /dev/null
+++ b/scripts/remove_paired_mobis
@@ -0,0 +1,19 @@
+#/bin/bash
+
+# Looks for all MOBI files in the current directory and removes
+# those for which an identically named EPUB exists in the current
+# directory also.
+# In other words, for every ebook in the current directory that
+# exists as both an EPUB and a MOBI/LIT/PRC/AZW3, it removes the latter.
+
+for ext in mobi prc lit azw3 rtf pdb fb2
+do
+ echo "deleting paired ${ext}s"
+ for i in *.$ext
+ do
+ if [[ -e "${i%.$ext}.epub" ]]
+ then
+ rm -v "$i"
+ fi
+ done
+done