Skip to content

Instantly share code, notes, and snippets.

@fizbin
Created March 24, 2022 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fizbin/74c2e8d30bfbc796604aae77c920b635 to your computer and use it in GitHub Desktop.
Save fizbin/74c2e8d30bfbc796604aae77c920b635 to your computer and use it in GitHub Desktop.
Launch python 3 for a git hook on any platform
#! /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