From 67dc431aa257c9307ccac4e43007626d22866b7b Mon Sep 17 00:00:00 2001 From: fbt Date: Sun, 25 May 2025 11:14:31 +0000 Subject: [PATCH] Add a step that converts files if asked to Signed-off-by: fbt --- ufwd | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/ufwd b/ufwd index c94aa5a..8ac2542 100755 --- a/ufwd +++ b/ufwd @@ -11,14 +11,33 @@ err() { echo "$*" >&2; } usage() { printf 'Usage: ufwd [-hn] [-d workdir] -D [check delay]\n' - printf ' -h # Show this message.\n' - printf ' -n # Enable notifications with notify-send. Must be installed.\n' - printf ' -d [path] # Set the dir that is to be watched.\n' - printf ' -s # Push the file url into the clipboard.\n' + printf ' -h # Show this message.\n' + printf ' -n # Enable notifications with notify-send. Must be installed.\n' + printf ' -d [path] # Set the dir that is to be watched.\n' + printf ' -s # Push the file url into the clipboard.\n' + printf ' --magick # Convert files of `type` into `format` with magick.\n' } upload() { - declare file=$1; shift + declare file=$1 file_type _type _target upload_output upload_return + shift + + if [[ $cfg_magick ]]; then + file_type=$(file -ib "$file") + file_type="${file_type%;*}" + + for x in "${cfg_magick[@]}"; do + _type="${x%:*}" + _target="${x#*:}" + + [[ $_type == "$file_type" ]] && { + magick "$file" "${file%.*}.$_target" + rm -v "$file" + + exit 0 # The next instance of the script will pick the file up. + } + done + fi upload_output=$( ufw -R "$@" "$file" ) upload_return=$? @@ -47,6 +66,7 @@ main() { (--clipboard|-c) flag_enable_clipboard=1;; (--workdir|-d) cfg_workdir+=( "$2" ); shift;; + (--magick) cfg_magick+=( "$2" ); shift;; (--) shift; break;; (-*) err "Unknown key: $1"; usage; return 1;;