Dotenv CLI
As a small weekend project I wrote my own dotenv
CLI.
Dotenv-CLI is a simple package that provides the dotenv
command. It reads
the .env
file from the current directory puts the contents in the
environment and executes the given command.
Example .env
file:
BASIC=basic basic
export EXPORT=foo
EMPTY=
INNER_QUOTES=this 'is' a test
INNER_QUOTES2=this "is" a test
TRIM_WHITESPACE= foo
KEEP_WHITESPACE=" foo "
MULTILINE="multi\nline"
# some comment
becomes:
$ dotenv env
BASIC=basic basic
EXPORT=foo
EMPTY=
INNER_QUOTES=this 'is' a test
INNER_QUOTES2=this "is" a test
TRIM_WHITESPACE=foo
KEEP_WHITESPACE= foo
MULTILINE=multi
line
where env
is a simple command that outputs the current environment
variables. A dotenv
CLI comes in handy if you follow the 12 factor
app methodology or just need to run a program locally with
specific environment variables set.
While dotenv-cli is certainly not the first dotenv
implementation, this one is written in Python and has no external dependencies
except Python itself. It also provides a bash completion, so you can prefix
any command with dotenv
while still be able to use completion:
$ dotenv make <TAB>
all clean docs lint release test
Since there’s also some other popular shells out there and I already struggled
writing the simple bash completion script, it would be very nice if some more
experienced zsh
-, fish
-, etc.- users could help me out in providing
completions for them as well.
dotenv-cli
is available on Debian and Ubuntu:
$ sudo apt-get install python3-dotenv-cli
and on PyPi as well:
$ pip install dotenv-cli