Last active
October 24, 2015 23:50
-
-
Save monkeydom/e6b38e8c34f3147a08c6 to your computer and use it in GitHub Desktop.
Script to be used in a hashbang to conditionally compile and then run the swift script referenced. usage #!/usr/bin/env swiftc.sh in your swift file, and put in path
This file contains 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/sh | |
SWIFT=$(/usr/bin/env xcrun -f swift) | |
SCRIPTPATH=$1 | |
COMPILEDPATH="$SCRIPTPATH.o" | |
SDKPATH=$(/usr/bin/env xcrun --show-sdk-path --sdk macosx) | |
#compile if necessary | |
if [ $SCRIPTPATH -nt $COMPILEDPATH ]; then | |
$SWIFT -o "$COMPILEDPATH" -sdk "$SDKPATH" "$SCRIPTPATH" | |
if [ $? -ne 0 ]; then | |
exit $? | |
fi | |
fi | |
# ${@:n} passes on all arguments, sarting with the nth, "${@:n}" makes it work iwth escaped arguments as well (spaces, etc) | |
$COMPILEDPATH "${@:2}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
./$COMPILEDPATH ${@:2}
For those of us who don't put "." in the $PATH...