[PATCH 2/3] bash completion: refactor --strategy completion
- From
Jay Soffian <jaysoffian@gmail.com>
- Date
- Mar 6, 2009, 04:39 UTC
- Message-ID
- <2d83927582e9eed004b9fd12b77105a184277229.1236314073.git.jaysoffian@gmail.com>
- In-Reply-To
- <cover.1236314073.git.jaysoffian@gmail.com>
The code to complete --strategy was duplicated between _git_rebase and _git_merge, and is about to gain a third caller (_git_pull). This patch factors it into its own function.
Signed-off-by: Jay Soffian <jaysoffian@gmail.com> --- contrib/completion/git-completion.bash | 37 ++++++++++++++++--------------- 1 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index b347fdd..8924185 100755 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -440,6 +440,22 @@ __git_complete_remote_or_refspec () esac } +__git_complete_strategy () +{ + case "${COMP_WORDS[COMP_CWORD-1]}" in + -s|--strategy) + __gitcomp "$(__git_merge_strategies)" + return 1 + esac + case "$cur" in + --strategy=*) + __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}" + return 1 + ;; + esac + return 0 +} + __git_all_commands () { if [ -n "$__git_all_commandlist" ]; then @@ -1086,17 +1102,10 @@ _git_log () _git_merge () { + __git_complete_strategy && return + local cur="${COMP_WORDS[COMP_CWORD]}" - case "${COMP_WORDS[COMP_CWORD-1]}" in - -s|--strategy) - __gitcomp "$(__git_merge_strategies)" - return - esac case "$cur" in - --strategy=*) - __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}" - return - ;; --*) __gitcomp " --no-commit --no-stat --log --no-log --squash --strategy @@ -1165,16 +1174,8 @@ _git_rebase () __gitcomp "--continue --skip --abort" return fi - case "${COMP_WORDS[COMP_CWORD-1]}" in - -s|--strategy) - __gitcomp "$(__git_merge_strategies)" - return - esac + __git_complete_strategy && return case "$cur" in - --strategy=*) - __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}" - return - ;; --*) __gitcomp "--onto --merge --strategy --interactive" return
-- 1.6.2.rc2.332.g5d21b