Project handling for command line scripts

Here is a pattern that I use sometimes:

#!/bin/bash
# -*- mode: julia -*-
#=
JULIA="${JULIA:-julia --color=yes --startup-file=no}"
export JULIA_PROJECT="$(dirname ${BASH_SOURCE[0]})"

set -ex
${JULIA} -e 'using Pkg; Pkg.instantiate()'

export JULIA_LOAD_PATH="@"
exec ${JULIA} "${BASH_SOURCE[0]}" "$@"
=#
using Whatever
...

Ref: https://docs.julialang.org/en/latest/manual/faq/#How-do-I-pass-options-to-julia-using-#!/usr/bin/env?-1

Not sure if this is less overkill, though.

8 Likes