Nix-polyloader: small stub for running py with or without nix

I’m running out of juice for today, so I’ll just leave this here:

Continuing with the tradition of mildly funky shebang things, GitHub - deliciouslytyped/nix-polyloader: A small bash/py polyglot stub for shebang-getting deps when on nix, otherwise - not; for portability is a couple line bash/python stub that lets you execute a python script whether you have nix-shell to get your dependencies, or not.

Python:

#! /usr/bin/env bash
#! nix-shell -i python -p "python38.withPackages (p: with p; [ lxml ])" -v

# nix-polyloader

"""true"
SCRIPT_PATH="$(realpath -s "$BASH_SOURCE")"
if ! command -v nix-shell; then
  exec python "$SCRIPT_PATH" "$@"
else
  exec nix-shell "$SCRIPT_PATH" "$@"
fi
"true"""

# Python starts

bash:

#! /usr/bin/env bash
#! nix-shell -i python -p "python38.withPackages (p: with p; [ lxml ])" -v

# nix-polyloader

"""true"
SCRIPT_PATH="$(realpath -s "$BASH_SOURCE")"
if ! command -v nix-shell; then
  exec python "$SCRIPT_PATH" "$@"
else
  exec nix-shell "$SCRIPT_PATH" "$@"
fi
"true"""

# Python starts