Skip to content

Instantly share code, notes, and snippets.

@ab
Created March 31, 2023 14:54
Show Gist options
  • Save ab/8088d6e893b1e0bafe7a8c0dd342951e to your computer and use it in GitHub Desktop.
Save ab/8088d6e893b1e0bafe7a8c0dd342951e to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ $# -eq 0 ]; then
cat >&2 <<EOM
usage: poetry-shebang FILE
Install this script somewhere on your \$PATH -- such as /usr/local/bin/ -- to
be able to seamlessly run Python scripts under \`poetry run\` without having to
type that out.
Add this shebang to your script, and make it executable:
#!/usr/bin/env poetry-shebang
EOM
exit 1
fi
script="$1"
shift
script_folder="$(dirname "$script")"
script_file="$(basename "$script")"
cd "$script_folder" && exec poetry run python "$script_file" "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment