5 releases
0.2.3 | Aug 18, 2021 |
---|---|
0.2.2 | Aug 12, 2021 |
0.2.1 | Aug 3, 2021 |
0.2.0 | Jul 31, 2021 |
0.1.0 | Jul 27, 2021 |
#34 in #config-toml
16KB
275 lines
bagex
Synopsis
bagex
serves as an entrance for programs, it manages environment variables
for the programs according to a configuration file.
Configuration
The configuration file is in toml format,
and consists of 3 parts: path
, env
, and exe
.
path
: It is an array of paths, which will be prepended to the environment variable$PATH
whenbagex
tries to find a executable.env
: This section creates multiple one-to-many mappings from an environment variable to some executables.exe
: This section creates multiple one-to-many mappings from an executable to some environment variables.
An illustrative example configuration can be found here.
Usage
bagex
takes an executable name as its argument, and tries to read its
configuration from $XDG_CONFIG_HOME/bagex/config.toml
if the environment
variable XDG_CONFIG_HOME
is set, otherwise it tries to read
$HOME/.config/bagex/config.toml
. Optionally use -c|--config-file
to
specify the configuration file to read. Example usage:
$ cat config.toml
[env.answer_to_the_ultimate_question_of_life_the_universe_and_everything]
42 = [
"printenv",
]
[exe.printenv]
some_random_string = "YmFnZXgK"
pi = 3.14
$ bagex -c config.toml printenv
[..truncated..]
answer_to_the_ultimate_question_of_life_the_universe_and_everything=42
pi=3.14
some_random_string=YmFnZXgK
To add arguments for the requested executable (printenv
in the above
example), append the arguments after a double dash (--
):
$ bagex -c ./config.toml bagex -- --version
bagex 0.1.0
Use -d|--dry-run
to show the command to run and abort:
$ bagex -c ./config -d echo -- -en "Hello world!"
/sbin/echo "-en" "Hello world!"
Use cases
Systemd services
It is quite convenient to set a process' environment in a systemd service,
but every time the environment has to change, one must run systemctl [--user] daemon-reload
after changing the .service
file, then call systemctl [--user] restart foo.service
to update the running environment of the
program.
bagex
makes this process even more convenient by specifying the environment
of a program in a separate config file, so that each time the environment is
changed in bagex
's config, only a systemctl [--user] restart foo.service
has to be called.
Application launchers (like rofi, sxhkd, etc.)
bagex
can be used as a backend for application launchers. The functionality
bagex
provides is basically an application launcher with an environment
managing module. After creating the configuration file, invoke bagex through
the application launchers so that the environment variables are the way the
config file specifies.
License
Dependencies
~9–19MB
~240K SLoC