diff --git a/guzzy/__init__.py b/guzzy/__init__.py index 243c967..ed6be47 100644 --- a/guzzy/__init__.py +++ b/guzzy/__init__.py @@ -1,36 +1,13 @@ -from os import listdir, path -from argparse import ArgumentParser -from subprocess import call - -dir_path = path.join(path.dirname(path.realpath(__file__)), "commands") - - -def parse_comments(command: str) -> dict: - with open(path.join(dir_path, f"{command}.sh"), "r") as f: - lines = f.read().splitlines() - comments = [ - l.replace("# ", "") - for l in lines - if l.startswith("#") and not l.startswith("#!") - ] - return {key: val.strip() for key, val in (line.split(":") for line in comments)} +from pysheller import PySheller +from os import chdir +from os.path import dirname, realpath, join def main(): - commands = [x.replace(".sh", "") for x in listdir(dir_path)] + dir_path = dirname(realpath(__file__)) - parser = ArgumentParser( - prog="guzzy", + PySheller( + name="guzzy", description="Interactive CLI git client inside fzf.", - allow_abbrev=False, + commands_dir=join(dir_path, "commands"), ) - subparsers = parser.add_subparsers(dest="command", required=True) - - subcommands = {} - for cmd in commands: - p = parse_comments(cmd) - subcommands[cmd] = subparsers.add_parser(cmd, help=p["help"]) - - args = parser.parse_args() - - call(path.join(dir_path, f"{args.command}.sh"), shell=True) diff --git a/guzzy/commands/diff.sh b/guzzy/commands/diff.sh index 12263a6..b8afccb 100755 --- a/guzzy/commands/diff.sh +++ b/guzzy/commands/diff.sh @@ -1,5 +1,5 @@ #!/bin/sh -# help: list modified, uncommited files and diff for each one +# help : list modified, uncommited files and diff for each one git ls-files --modified | fzf --preview 'git diff --color=always {}' diff --git a/guzzy/commands/file-history.sh b/guzzy/commands/file-history.sh index d7f1679..2759a48 100755 --- a/guzzy/commands/file-history.sh +++ b/guzzy/commands/file-history.sh @@ -1,6 +1,7 @@ #!/bin/sh -# help: list all commits where file was changed and display diff for each one +# help : list all commits where file was changed and display diff for each one +# arg1 : filename - name of the file to show history of file_name="$1" diff --git a/guzzy/commands/files.sh b/guzzy/commands/files.sh index 7d5f62b..1da1ff4 100755 --- a/guzzy/commands/files.sh +++ b/guzzy/commands/files.sh @@ -1,6 +1,7 @@ #!/bin/sh -# help: list all files in specified commit/tag/branch with preview +# help : list all files in specified commit/tag/branch with preview +# arg1 : commit - commit hash, branch or tag name [ "$1" ] && commit_hash="$1" || commit_hash="HEAD" diff --git a/guzzy/commands/log.sh b/guzzy/commands/log.sh index 0ccfab2..73443d3 100755 --- a/guzzy/commands/log.sh +++ b/guzzy/commands/log.sh @@ -1,6 +1,6 @@ #!/bin/sh -# help: list all commits with diff for changes fot each one +# help : list all commits with diff for changes fot each one CWD="$(dirname "$(readlink -f "$0")")" diff --git a/guzzy/commands/tags.sh b/guzzy/commands/tags.sh index 6bb1c62..8e90884 100755 --- a/guzzy/commands/tags.sh +++ b/guzzy/commands/tags.sh @@ -1,6 +1,6 @@ #!/bin/sh -# help: list all tags with tag messages +# help : list all tags with tag messages git --no-pager tag --sort=-taggerdate -l | fzf --preview "git --no-pager tag -l {} --format='%(contents)'"