Skip to content

Instantly share code, notes, and snippets.

@sixtyfive
Last active August 11, 2021 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sixtyfive/1bc1a367299f8f57b6b174997a58bd4c to your computer and use it in GitHub Desktop.
Save sixtyfive/1bc1a367299f8f57b6b174997a58bd4c to your computer and use it in GitHub Desktop.
Takes the path to an OpenSCAD .scad file as input and copies a GitHub Gist URL onto your Xorg clipboard as output. The Gist will contain the OpenSCAD source file as well as an in-browser rendering of the (ASCII) STL file. Works for me, but open to PRs, er, comments. Please share alike as you see fit.
#!/bin/bash
# Prerequisites: ###
# - OpenSCAD #
# - GitHUB CLI #
# - xclip #
# ################ #
[[ -z $1 || "${1: -5}" != ".scad" ]] && (echo "Usage: gist-scad <path to OpenSCAD .scad file>"; kill $$; exit 1)
OPENSCAD=$(which openscad 2>/dev/null)
[[ -z $OPENSCAD ]] && OPENSCAD="flatpak run org.openscad.OpenSCAD"
SCADFILE="$1"
STLFILE="$(echo $SCADFILE | sed s/\.scad/.ascii.stl/)"
[[ -e "$SCADFILE" ]] && (
echo -n "Rendering into $STLFILE..."
$OPENSCAD --export-format asciistl -o "$STLFILE" "$SCADFILE" >/dev/null 2>&1; echo " done")
echo -n "Uploading..."
URL=$(gh gist create "$SCADFILE" "$STLFILE" 2>&1 | grep 'https')
echo " here's your link: $URL (also copied to clipboard)"
echo $URL | xclip -sel c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment