From 6f84cd97276451e5d4a612cd9fcfad5de757f2db Mon Sep 17 00:00:00 2001 From: Phantop Date: Sat, 3 Jun 2023 12:00:25 -0400 Subject: [PATCH] fish: ao3 authors; bin: pad jpeg --- bin/aliases | 1 + bin/padjpeg | 29 +++++++++++++++++++++++++++++ fish/functions/ao3.fish | 4 +++- 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100755 bin/padjpeg diff --git a/bin/aliases b/bin/aliases index 1bd2c59..6fae223 100755 --- a/bin/aliases +++ b/bin/aliases @@ -47,6 +47,7 @@ a rmlinks 'ff -t l -x rm' a qb 'qutebrowser --target auto' a re 'systemctl reboot -i' a s 'sudo env "PATH=$PATH"' +a ssh 'kitty +kitten ssh' a sus 'systemctl suspend' a tar bsdtar a tcsv 'curl -sL http://torrents-csv.ml/service/search?q=$argv | jq ".[]|.name,.infohash,.seeders";:' diff --git a/bin/padjpeg b/bin/padjpeg new file mode 100755 index 0000000..b247872 --- /dev/null +++ b/bin/padjpeg @@ -0,0 +1,29 @@ +#!/usr/bin/env sh +#shellcheck disable=SC2034 +set -e # exit on failure +IFS=$(printf '\n\t') # smarter ifs + +test "$RATIOW" || RATIOW=16 +test "$RATIOH" || RATIOH=9 +imageh=$(identify -format %h "$1") +imagew=$(identify -format %w "$1") +des_ratio=$(printf '3 k %u %u / p' "$RATIOW" "$RATIOH" | dc) +img_ratio=$(printf '3 k %u %u / p' "$imagew" "$imageh" | dc) + +wide="$(echo "$img_ratio > $des_ratio" | bc )" +if [ "$wide" -gt 0 ] ; then + mv "$1" ".$1_padjpegtmp.jpg" + jpegtran -rotate 90 -outfile "$1" ".$1_padjpegtmp.jpg" + imageh=$(identify -format %h "$1") + imagew=$(identify -format %w "$1") + des_ratio=$(printf '3 k %u %u / p' "$RATIOH" "$RATIOW" | dc) +fi + +des_width=$(printf '1 k %f %u * p' "$des_ratio" "$imageh" | dc | cut -d. -f1) +offset=$(printf '%u %u - 2 / p' "$des_width" "$imagew" | dc) +jpegtran -crop "$des_width"f+"$offset" -outfile "tran_$1" "$1" + +if [ "$wide" -gt 0 ] ; then + mv ".$1_padjpegtmp.jpg" "$1" + jpegtran -rotate 270 -outfile "tran_$1" "tran_$1" +fi diff --git a/fish/functions/ao3.fish b/fish/functions/ao3.fish index 9c6a2e2..c34d2ac 100644 --- a/fish/functions/ao3.fish +++ b/fish/functions/ao3.fish @@ -1,6 +1,8 @@ function ao3 grep works/.\*/b $argv | cut -d/ -f3 | uniq | parallel curl -OJL ao3.org/downloads/{}/1.epub for i in *.epub - mv $i (tar Oxf $i content.opf | pup | grep -A1 -m1 dc:title | tail -1 | sed 's/^ *//' | tr -d /).epub + set title (tar Oxf $i content.opf | pup | grep -A1 -m1 dc:title | tail -1 | sed 's/^ *//' | tr -d /) + set creator (tar Oxf $i content.opf | pup | grep -A1 -m1 dc:creator | tail -1 | sed 's/^ *//' | tr -d /) + mv $i "$creator - $title.epub" end end