Created
March 24, 2022 13:46
-
-
Save fizbin/74c2e8d30bfbc796604aae77c920b635 to your computer and use it in GitHub Desktop.
Launch python 3 for a git hook on any platform
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 | |
''''test x != "-*- mode: python -*-" | |
case "`python --version 2>/dev/null`" in | |
[Pp]"ython 3"*) exec python "$0" "$@" ;; | |
esac | |
case "`python3 --version 2>/dev/null`" in | |
[Pp]"ython 3"*) exec python3 "$0" "$@" ;; | |
esac | |
case "`py -3 --version 2>/dev/null`" in | |
[Pp]"ython 3"*) exec py -3 "$0" "$@" ;; | |
esac | |
echo "Unable to find python 3 on the PATH; failing" | |
exit 1 | |
# ''' | |
# | |
# Copy-paste the above text to the top of a python 3 file and it'll launch the file | |
# with python 3 regardless of platform, assuming that the file is initially started | |
# with /bin/sh. This was designed for use in git hooks and merge drivers, but may | |
# be useful elsewhere too. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment