56 lines
1.1 KiB
Bash
Executable File
56 lines
1.1 KiB
Bash
Executable File
#!/usr/bin/env zsh
|
|
|
|
functipn imup() {
|
|
for arg in ${@}; do
|
|
case "${arg}" in
|
|
-h|--help)
|
|
cat << EOF
|
|
Normalize, strip, and upload images via scp.
|
|
|
|
Usage: imup [ -h | --help ] [SRC ...]
|
|
|
|
SRC may be a path or url to an image file, or a special value.
|
|
|
|
'-' read from stdin.
|
|
'+' read from the system clipboard.
|
|
|
|
If no SRC is provided, read from the system clipboard.
|
|
EOF
|
|
return
|
|
;;
|
|
esac
|
|
done
|
|
|
|
local root="$(mktemp -d)"
|
|
trap "rm -r '$root'" EXIT
|
|
|
|
local -a files
|
|
|
|
for src in ${@:-+}; do
|
|
local name="$(uuidgen).webp"
|
|
local file="$root/$name"
|
|
|
|
case $src in
|
|
+)
|
|
xclip -o -selection clipboard -t image/png > "$file" || continue
|
|
convert "$file" -strip "WEBP:$file" || continue
|
|
src="<clipboard>"
|
|
;;
|
|
-)
|
|
convert - -strip "WEBP:$file" || continue
|
|
src="<stdin>"
|
|
;;
|
|
*)
|
|
convert "$src" -strip "WEBP:$file" || continue
|
|
;;
|
|
esac
|
|
|
|
files+=("$file")
|
|
echo "${IMUP_URL:?}/$name ($src)"
|
|
done
|
|
|
|
[[ ! -z $files ]] && scp "${files[@]}" "${IMUP_SCP_DIR:?}/"
|
|
}
|
|
|
|
imup "$@"
|