提交 d0738626 编写于 作者: M Mislav Marohnić

Make bash completion script compatible with bash v3

Previus version was written for bash v4 and was causing syntax error
when used with older versions of bash that still ship with most systems.

References 3565094d
Closes #359
上级 c3fe6784
......@@ -54,11 +54,10 @@ EOF
# hub browse [-u] [--|[USER/]REPOSITORY] [SUBPAGE]
_git_browse() {
local i c=2 u=-u repo subpage
local -A subpages
subpages["/"]="commits issues tree wiki pulls branches stargazers
local subpages_="commits issues tree wiki pulls branches stargazers
contributors network network/ graphs graphs/"
subpages["/network"]="members"
subpages["/graphs"]="commit-activity code-frequency punch-card"
local subpages_network="members"
local subpages_graphs="commit-activity code-frequency punch-card"
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
......@@ -81,10 +80,11 @@ EOF
case "$cur" in
*/*)
local pfx="${cur%/*}" cur_="${cur#*/}"
__gitcomp "${subpages[/$pfx]}" "$pfx/" "$cur_"
local subpages_var="subpages_$pfx"
__gitcomp "${!subpages_var}" "$pfx/" "$cur_"
;;
*)
__gitcomp "$u ${subpages[/]}"
__gitcomp "$u ${subpages_}"
;;
esac
else
......@@ -184,8 +184,9 @@ EOF
case "$i" in
-d|-h)
((c++))
;;&
-p|-d|-h)
flags=${flags/$i/}
;;
-p)
flags=${flags/$i/}
;;
*)
......@@ -232,8 +233,9 @@ EOF
case "$i" in
-m|-F|-i|-b|-h)
((c++))
;;&
-f|-m|-F|-i|-b|-h)
flags=${flags/$i/}
;;
-f)
flags=${flags/$i/}
;;
esac
......@@ -248,7 +250,10 @@ EOF
# Uncomment the following line when 'owner/repo:[TAB]' misbehaved
#_get_comp_words_by_ref -n : cur
__gitcomp_nl "$(__hub_heads)"
__ltrim_colon_completions "$cur"
# __ltrim_colon_completions "$cur"
;;
-F)
COMPREPLY=( "$cur"* )
;;
-f|*)
__gitcomp "$flags"
......
......@@ -20,6 +20,11 @@ Feature: bash tab-completion
When I press <Tab> again
Then the completion menu should offer "-F -b -f -h -i -m"
Scenario: Doesn't offer already used pull-request flags
When I type "git pull-request -F myfile -h mybranch -" and press <Tab>
When I press <Tab> again
Then the completion menu should offer "-b -f -i -m"
Scenario: Browse to issues
When I type "git browse -- i" and press <Tab>
Then the command should expand to "git browse -- issues"
......
......@@ -27,11 +27,11 @@ git_prefix = lambda {
}
git_distributed_zsh_completion = lambda {
git_prefix.call + 'share/zsh/site-functions/_git'
git_prefix.call + 'share/git-core/contrib/completion/git-completion.zsh'
}
git_distributed_bash_completion = lambda {
git_prefix.call + 'etc/bash_completion.d/git-completion.bash'
git_prefix.call + 'share/git-core/contrib/completion/git-completion.bash'
}
link_completion = Proc.new { |from, name|
......@@ -113,7 +113,7 @@ World Module.new {
def tmux_wait_for_completion
# bash can be pretty slow
sleep 0.4
sleep 0.6
end
def tmux_completion_menu
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册