~kris/dots

srice

ref: 9f828eb14bdd54d2c4fd8a3b2c90253021df3152 srice/.local/bin/blog-screenshot -rwxr-xr-x 539 bytes
9f828eb1 — Kris Yotam mksh: backslash-escape commands in history hook to bypass module aliases (wc=tokei, tr=transmission-remote, cat=bat) 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env sh
set -eu

if [ "$#" -lt 1 ]; then
  printf 'usage: blog-screenshot URL [output.png]\n' >&2
  exit 2
fi

url=$1
out=${2:-"screenshots/$(printf '%s' "$url" | sed -e 's#^https\?://##' -e 's#[^A-Za-z0-9._-]#-#g' -e 's#-*$##').png"}
mkdir -p "$(dirname "$out")"

if command -v shot-scraper >/dev/null 2>&1; then
  shot-scraper "$url" -o "$out"
elif command -v npx >/dev/null 2>&1; then
  npx --yes playwright screenshot "$url" "$out"
else
  printf 'Need shot-scraper or npx playwright.\n' >&2
  exit 1
fi

printf '%s\n' "$out"