Skip to content

Instantly share code, notes, and snippets.

@sverweij
Last active January 22, 2025 15:12
Show Gist options
  • Save sverweij/406b7b5e7b164bc06d0861cb8833a518 to your computer and use it in GitHub Desktop.
Save sverweij/406b7b5e7b164bc06d0861cb8833a518 to your computer and use it in GitHub Desktop.
Scrappy script to open stdin into whichever is associated with .html extensions (MacOS)
#!/bin/bash
set -e
RANDOMNAME=$(mktemp).html || exit 1
cat /dev/stdin > $RANDOMNAME
open $RANDOMNAME
# to open with an other browser (or program) replace the above line with
# something like ...
# open -a safari $RANDOMNAME
# open -a firefox $RANDOMNAME
# inelegant and not foolproof (i.e. if the browser takes longer than the
# sleep time to open the file, it'll be _gone_)
trap "sleep 2.4s && rm $RANDOMNAME &" EXIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment