From 0d03db771b48f7d90cf96560c32048001809e84f Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 10 Jan 2018 16:08:04 +0200 Subject: Add: a bunch of new scripts --- with | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 with (limited to 'with') diff --git a/with b/with new file mode 100755 index 0000000..469d6bd --- /dev/null +++ b/with @@ -0,0 +1,35 @@ +#!/usr/bin/python3 + + +import os + + +import cliapp +import yaml + + +class With(cliapp.Application): + + def add_settings(self): + self.settings.string( + ['env-file', 'e'], + 'read environment description from FILE', + metavar='FILE', + default=os.path.expanduser('~/.config/with-envs/environments.yaml')) + + def process_args(self, args): + env_name = args[0] + argv = args[1:] + + envs = self.get_environments() + print(envs) + env = dict(os.environ) + env.update(envs[env_name]) + cliapp.runcmd(argv, env=env, stdout=None, stderr=None) + + def get_environments(self): + filename = self.settings['env-file'] + return yaml.safe_load(open(filename)) + + +With().run() -- cgit v1.2.1