fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1#!/bin/sh 2 3# Modern Linux and macOS systems commonly only have a thing called `python3` and 4# not `python`, while Windows commonly does not have `python3`, so we cannot 5# directly use python in the x.py shebang and have it consistently work. Instead we 6# have a shell script to look for a python to run x.py. 7 8set -eu 9 10# syntax check 11sh -n "$0" 12 13realpath() { 14 if [ -d "$1" ]; then 15 CDPATH='' command cd "$1" && pwd -P 16 else 17 echo "$(realpath "$(dirname "$1")")/$(basename "$1")" 18 fi 19} 20 21xpy=$(dirname "$(realpath "$0")")/x.py 22 23# On Windows, `py -3` sometimes works. We need to try it first because `python3` 24# sometimes tries to launch the app store on Windows. 25for SEARCH_PYTHON in py python3 python python2; do 26 if python=$(command -v $SEARCH_PYTHON) && [ -x "$python" ]; then 27 if [ $SEARCH_PYTHON = py ]; then 28 extra_arg="-3" 29 else 30 extra_arg="" 31 fi 32 exec "$python" $extra_arg "$xpy" "$@" 33 fi 34done 35 36python=$(bash -c "compgen -c python" | grep '^python[2-3]\.[0-9]\+$' | head -n1) 37if ! [ "$python" = "" ]; then 38 exec "$python" "$xpy" "$@" 39fi 40 41echo "$0: error: did not find python installed" >&2 42exit 1