Last active
April 23, 2024 15:42
-
-
Save noel-yap/814ee650070336246443 to your computer and use it in GitHub Desktop.
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
# Allows one to have a multi-line shebang just like in Scala. Just as in Scala, be sure to end the multi-line shebang with a !#. | |
# example usage: trampoline "${GRADLE_HOME}/bin/gradle" "$@" | |
function trampoline() { | |
local command=("$@") | |
umask 077 | |
tmpdir="$(mktemp -d -t $$.XXXXXXXXXXXXXXXX)" | |
trap 'rm -rf -- "${tmpdir}"' INT TERM HUP EXIT | |
tmpfile="${tmpdir}/$(basename $0)" | |
command=("${command[@]/$0/${tmpfile}}") | |
sed -e '1,/^!#$/d' "$0" >"${tmpfile}" && "${command[@]}" | |
status=${PIPESTATUS[0]} | |
exit ${status} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment