Crates.io | bagex |
lib.rs | bagex |
version | 0.2.3 |
source | src |
created_at | 2021-07-27 13:49:12.472169 |
updated_at | 2021-08-18 17:09:18.887096 |
description | Manage environment of executables with ease |
homepage | |
repository | https://github.com/blurgyy/bagex |
max_upload_size | |
id | 427978 |
size | 36,069 |
bagex
serves as an entrance for programs, it manages environment variables
for the programs according to a configuration file.
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
when bagex
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.
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!"
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.
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.