Skip to content

Instantly share code, notes, and snippets.

@taikedz
Created October 17, 2023 10:46
Show Gist options
  • Save taikedz/5ba65a45b6eeab954fdcedd8f93bc41f to your computer and use it in GitHub Desktop.
Save taikedz/5ba65a45b6eeab954fdcedd8f93bc41f to your computer and use it in GitHub Desktop.
rustr - run rust source file as an executable script
#!/usr/bin/env bash
# Use this `rustr` script as a shebang target.
# put `rustr` somewhere on your PATH
filename="$1"; shift
temp="$(mktemp)"
rmtemp() { rm "$temp"; }
touch "$temp"
trap rmtemp exit
if rustc "$filename" -o "$temp"; then
chmod 700 "$temp"
"$temp" "$@"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment