From fbf4141fb339c3a11e02d2d72d092557ca0f8c7a Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 26 Apr 2024 23:55:20 +0200 Subject: [PATCH] environ --- cd/__init__.py | 9 ++++++++- cd/__main__.py | 6 ++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cd/__init__.py b/cd/__init__.py index 572b36c..de206f7 100644 --- a/cd/__init__.py +++ b/cd/__init__.py @@ -1,7 +1,14 @@ import os +COMMANDS_PREFIX = 'cd-' + + +def cd_list_environment: + for variable, value in os.environ: + print(variable, value) + def install_commands(path): user = '/usr/local/bin' for command in ['list-environment']: - os.symlink(path, os.path.join(user, f'cd-{command}')) + os.symlink(path, os.path.join(user, f'{COMMANDS_PREFIX}{command}')) diff --git a/cd/__main__.py b/cd/__main__.py index 50e77b6..c93b684 100755 --- a/cd/__main__.py +++ b/cd/__main__.py @@ -7,9 +7,11 @@ import cd if __name__ == '__main__': - command, *_ = sys.argv + command, *arguments = sys.argv command = os.path.basename(command) if command == '__main__.py': cd.install_commands(__file__) else: - print(command) + command = command.replace('-', '_') + function = getattr(cd, command) + function(*arguments)