From 2718a2e23a3e294f4261b0e8795ffe1e5f183089 Mon Sep 17 00:00:00 2001 From: "Amlesh Sivanantham (zamlz)" Date: Mon, 24 Dec 2018 15:18:44 -0800 Subject: [PATCH] Implemented git shell --- pubs/plugs/git/__init__.py | 0 pubs/plugs/git/git.py | 32 ++++++++++++++++++++++++++++++++ setup.py | 3 ++- 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 pubs/plugs/git/__init__.py create mode 100644 pubs/plugs/git/git.py diff --git a/pubs/plugs/git/__init__.py b/pubs/plugs/git/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pubs/plugs/git/git.py b/pubs/plugs/git/git.py new file mode 100644 index 0000000..3ee3fb8 --- /dev/null +++ b/pubs/plugs/git/git.py @@ -0,0 +1,32 @@ + +import subprocess +from pipes import quote as shell_quote + +from ...plugins import PapersPlugin + + +class GitPlugin(PapersPlugin): + + name = 'git' + + def __init__(self, conf): + self.description = "Run git commands in the pubs directory" + + def update_parser(self, subparsers, conf): + git_parser = self.parser(subparsers) + git_parser.set_defaults(func=self.command) + + def parser(self, parser): + self.parser = parser + p = parser.add_parser(self.name, help=self.description) + p.add_argument('arguments', nargs='*', help="look at man git") + return p + + def command(self, conf, args): + """Runs the git program in a shell""" + subprocess.call( + 'pubs_git() {{\ngit -C {} $@\n}}\npubs_git {}'.format( + conf['main']['pubsdir'], + ' '.join([shell_quote(a) for a in args.arguments]) + ), shell=True) + diff --git a/setup.py b/setup.py index aa0cded..190a98d 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,8 @@ setup( 'pubs.commands', 'pubs.templates', 'pubs.plugs', - 'pubs.plugs.alias'], + 'pubs.plugs.alias', + 'pubs.plugs.git'], entry_points={ 'console_scripts': [ 'pubs=pubs.pubs_cmd:execute',