Last active
August 11, 2021 21:02
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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