Giter Club home page Giter Club logo

bagex's Introduction

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 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.

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

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.