Initial commit. Add imup zsh tool.

This commit is contained in:
David Allemang
2026-01-23 09:51:09 -05:00
commit ac78933b02
5 changed files with 142 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
/.idea/
*.webp

82
README.md Normal file
View File

@@ -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 (<clipboard>)
```
- 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 (<stdin>)
```
## 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.

0
images/.gitkeep Normal file
View File

55
imup Executable file
View File

@@ -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="<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 "$@"

3
mise.toml Normal file
View File

@@ -0,0 +1,3 @@
[env]
IMUP_SCP_DIR = "{{ config_root }}/images"
IMUP_URL = "file://{{ config_root }}/images"