Last active
July 21, 2018 10:32
-
-
Save electrofelix/a77282312bcfc8eb1bcc1cd5a992aa03 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/bash_completion/git-upstream b/bash_completion/git-upstream | |
index 79dabb0..aa47985 100644 | |
--- a/bash_completion/git-upstream | |
+++ b/bash_completion/git-upstream | |
@@ -1,6 +1,6 @@ | |
eval "$(register-python-argcomplete git-upstream)" | |
# following automatically picked up if git bash completion active | |
-_git_upstream() { | |
+___git_upstream() { | |
# save originals | |
ORIG_COMP_LINE="${COMP_LINE}" | |
ORIG_COMP_POINT="${COMP_POINT}" | |
@@ -48,3 +48,19 @@ _git_upstream() { | |
unset NEW_COMP_WORDS | |
compopt +o nospace | |
} | |
+ | |
+_git_upstream() { | |
+ if [[ -n "$_ARC_DEBUG" ]] | |
+ then | |
+ echo "COMP_LINE=${COMP_LINE}" >&2 | |
+ echo "COMP_WORDS=${COMP_WORDS[@]}" >&2 | |
+ fi | |
+ | |
+ _python_argcomplete "git-upstream" | |
+ | |
+ if [[ -n "$_ARC_DEBUG" ]] | |
+ then | |
+ echo "COMPREPLY=${COMPREPLY[@]}" >&2 | |
+ fi | |
+ | |
+} | |
diff --git a/git_upstream/main.py b/git_upstream/main.py | |
index 161b771..b37131f 100644 | |
--- a/git_upstream/main.py | |
+++ b/git_upstream/main.py | |
@@ -42,11 +42,16 @@ except ImportError: | |
def build_parsers(): | |
- parser = argparse.ArgumentParser( | |
+ parent = parser = argparse.ArgumentParser( | |
prog='git-upstream', | |
description=__doc__.strip(), | |
epilog='See "%(prog)s help COMMAND" for help on a specific command.', | |
add_help=False) | |
+ | |
+ # hack for now | |
+ import re | |
+ if re.match("git .* upstream ", os.environ.get('COMP_LINE', '')): | |
+ parser = parser.add_subparsers().add_parser('upstream', add_help=False) | |
parser.add_argument('--version', action='version', | |
version='%(prog)s ' + __version__) | |
parser.add_argument('-h', '--help', action='help', | |
@@ -75,9 +80,9 @@ def build_parsers(): | |
script_cmdline = [program] | |
parser.set_defaults(script_cmdline=script_cmdline, | |
- parent_parser=weakref.proxy(parser)) | |
+ parent_parser=weakref.proxy(parent)) | |
- return subcommand_parsers, parser | |
+ return subcommand_parsers, parent | |
def setup_console_logging(options): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/bash_completion/git-upstream b/bash_completion/git-upstream | |
index 79dabb0..aa47985 100644 | |
--- a/bash_completion/git-upstream | |
+++ b/bash_completion/git-upstream | |
@@ -1,6 +1,6 @@ | |
eval "$(register-python-argcomplete git-upstream)" | |
# following automatically picked up if git bash completion active | |
-_git_upstream() { | |
+___git_upstream() { | |
# save originals | |
ORIG_COMP_LINE="${COMP_LINE}" | |
ORIG_COMP_POINT="${COMP_POINT}" | |
@@ -48,3 +48,19 @@ _git_upstream() { | |
unset NEW_COMP_WORDS | |
compopt +o nospace | |
} | |
+ | |
+_git_upstream() { | |
+ if [[ -n "$_ARC_DEBUG" ]] | |
+ then | |
+ echo "COMP_LINE=${COMP_LINE}" >&2 | |
+ echo "COMP_WORDS=${COMP_WORDS[@]}" >&2 | |
+ fi | |
+ | |
+ _python_argcomplete "git-upstream" | |
+ | |
+ if [[ -n "$_ARC_DEBUG" ]] | |
+ then | |
+ echo "COMPREPLY=${COMPREPLY[@]}" >&2 | |
+ fi | |
+ | |
+} | |
diff --git a/git_upstream/main.py b/git_upstream/main.py | |
index 161b771..b075707 100644 | |
--- a/git_upstream/main.py | |
+++ b/git_upstream/main.py | |
@@ -42,11 +42,22 @@ except ImportError: | |
def build_parsers(): | |
- parser = argparse.ArgumentParser( | |
- prog='git-upstream', | |
- description=__doc__.strip(), | |
- epilog='See "%(prog)s help COMMAND" for help on a specific command.', | |
- add_help=False) | |
+ # hack for now | |
+ import re | |
+ if re.match("git .* upstream ", os.environ.get('COMP_LINE', '')): | |
+ parent = parser = argparse.ArgumentParser( | |
+ prog='git-upstream', | |
+ description=__doc__.strip(), | |
+ epilog='See "%(prog)s help COMMAND" for help on a specific command.') | |
+ parser = parser.add_subparsers().add_parser('upstream', add_help=False) | |
+ else: | |
+ parent = parser = argparse.ArgumentParser( | |
+ prog='git-upstream', | |
+ description=__doc__.strip(), | |
+ epilog='See "%(prog)s help COMMAND" for help on a specific command.', | |
+ add_help=False | |
+ ) | |
+ | |
parser.add_argument('--version', action='version', | |
version='%(prog)s ' + __version__) | |
parser.add_argument('-h', '--help', action='help', | |
@@ -75,9 +86,9 @@ def build_parsers(): | |
script_cmdline = [program] | |
parser.set_defaults(script_cmdline=script_cmdline, | |
- parent_parser=weakref.proxy(parser)) | |
+ parent_parser=weakref.proxy(parent)) | |
- return subcommand_parsers, parser | |
+ return subcommand_parsers, parent | |
def setup_console_logging(options): |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment