commit ac78933b02558dc1d4d1695907fe1a0cae6a9834 Author: David Allemang Date: Fri Jan 23 09:51:09 2026 -0500 Initial commit. Add imup zsh tool. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6934d6e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/.idea/ +*.webp \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..0d5f943 --- /dev/null +++ b/README.md @@ -0,0 +1,82 @@ +A simple image uploader over SSH for static image hosting. + +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. + +## Sample Usage + +- From clipboard + ```zsh + $ imup + https://i.allemangd.dev/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.webp () + ``` + +- From file or URL + ```zsh + $ imup image.png ./image.jpeg 'https://example.com/image.webp' + https://i.allemangd.dev/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.webp (image.png) + https://i.allemangd.dev/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.webp (./image.jpeg) + https://i.allemangd.dev/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.webp (https://example.com/image.webp) + ``` + +- From stdin + ```zsh + $ convert image.png -resize 50% - | imup - + https://i.allemangd.dev/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.webp () + ``` + +## Installation and setup. + +This assumes you already have some hosted static files and ssh configured with write permissions to that directory. Images are copied to the host via `scp`. Thus authentication is deferred to other systems like VPN and SSH, and hosting is deferred to static web servers like nginx. This tool is only a convenience to normalize/strip image data and upload the files. + +The client depends on `imagemagick`, `scp`, and `xclip`. The host only needs to serve the static files. + +```zsh +apt install imagemagick ssh xclip +``` + +Copy `imup` to your `~/.zfunc` or somewhere eles on your zsh `fpath`. Add the configuration to your `~/.zshrc`: + +``` +autoload -Uz imup +export IMUP_SCP_DIR="..." # The target location. +export IMUP_URL="..." # The base url to access images. +``` + +For example, on my host `allemangd.dev` I have the following nginx static server: + +``` +# nginx config +server { + listen 80; + + server_name i.allemangd.dev; + + location / { + root /var/www/i.allemangd.dev/; + autoindex on; + } +} +``` + +I've granted write permissions to `/var/www/i.allemangd.dev` to my ssh user, and configured an ssh host for that user. + +``` +# ssh config +Host imup-host + HostName ... # only accessible via VPN + User ... + IdentifyFile ... +``` + +Then I set `IMUP_SCP_DIR="imup-host:/var/www/i.allemangd.dev` and `IMUP_URL=https://i.allemangd.dev` + +The development environment in `mise.toml` uses the local directory `./images/` for both of these to avoid hosting requirements while testing. diff --git a/images/.gitkeep b/images/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/imup b/imup new file mode 100755 index 0000000..999d5fe --- /dev/null +++ b/imup @@ -0,0 +1,55 @@ +#!/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="" + ;; + -) + convert - -strip "WEBP:$file" || continue + src="" + ;; + *) + convert "$src" -strip "WEBP:$file" || continue + ;; + esac + + files+=("$file") + echo "${IMUP_URL:?}/$name ($src)" + done + + [[ ! -z $files ]] && scp "${files[@]}" "${IMUP_SCP_DIR:?}/" +} + +imup "$@" diff --git a/mise.toml b/mise.toml new file mode 100644 index 0000000..6ac6c20 --- /dev/null +++ b/mise.toml @@ -0,0 +1,3 @@ +[env] +IMUP_SCP_DIR = "{{ config_root }}/images" +IMUP_URL = "file://{{ config_root }}/images"