It would be great to be able to use doppler in the script shebang. On MacOS, this actually works
#!/usr/bin/env doppler run -- /bin/bash
But then you get a nasty surprise on linux—no support for shebang args! So then you have to do this:
#!/bin/bash
set -euo pipefail
quoted_args="$(printf "${1+ %q}" "$@")"
bash_source="${BASH_SOURCE:-$0}"
bash_script="$(tail -n +9 $bash_source)"
bash_script_with_variables="bash_source=\"$bash_source\""$'\n'"quoted_args=\"$quoted_args\""$'\n'"$bash_script"
doppler run --command="/bin/bash -c '$bash_script_with_variables'"
exit 0
# workaround for #!/usr/bin/env doppler run -- /bin/bash
# - no arguments on linux https://stackoverflow.com/a/4304187
# - fail on error "set -euo pipefail"
# - quoted args https://superuser.com/a/403369
# - skip lines https://stackoverflow.com/a/604871
# - bash source https://stackoverflow.com/a/63072463
# - concat variables with newline https://stackoverflow.com/a/21145867
# - bash -c https://stackoverflow.com/a/20858440
It’s long and ugly, but it works. I’d love for doppler to have a bin script that is basically just bash with the right env.