Hi, On Sun, May 6, 2012 at 1:14 PM, SZEDER Gábor <szeder@xxxxxxxxxx> wrote: > On Sat, May 05, 2012 at 05:23:20PM +0200, Felipe Contreras wrote: >> This simplifies the completions, and makes it easier to define aliases: >> >> _GIT_complete gf git_fetch > > So, 'gf' is an alias for 'git fetch', for which the user would like to > use the completion for 'git fetch', right? But that completion > function is caled _git_fetch(), so the underscore prefix is missing > here. No, it's not missing: local name="${2-$1}" eval "$(typeset -f __git_func_wrap | sed -e "s/__git_func/_$name/")" complete -o bashdefault -o default -o nospace -F _${name}_wrap $1 2>/dev/null \ || complete -o default -o nospace -F _${name}_wrap $1 See how we add '_' before $name? There's not point in burdening the user with adding a prefix that will _always_ be there anyway. > Besides, this example won't work, because the completion for 'git > fetch' uses __git_complete_remote_or_refspec(), which in turn relies > on finding out the name of the git command from the word on the > command line, and it won't be able to do that from 'gf'. That's irrelevant, it's an example; replace with another command that doesn't use 'words', and it would work. > I remember we discussed this in an earlier round, and you even > suggested a possible fix (passing the command name as argument to > __git_complete_remote_or_refspec()). I think that's the right thing > to do here. Yeah, but I suggested that in order to avoid the eval and the typeset that I require for future future patches, but it turns out it's still needed anyway, so my suggestion is to have a 'cmd' variable that stores the command; __git_func_wrap would take the responsibility of doing that. >> + __git_func "$@" > > What is this "$@" for and why? None of the _git_<cmd>() functions > take any arguments, nor does _git() and _gitk(), and AFAICT Bash won't > pass any either. bash's complete passes 3 arguments. They might not be used, but it doesn't hurt to pass them either. >> +} >> + >> +_GIT_complete () >> +{ >> + local name="${2-$1}" >> + eval "$(typeset -f __git_func_wrap | sed -e "s/__git_func/_$name/")" > > Still don't like the subshell and sed here ... I haven't found any other way. As for the fix to 'git fetch' and others, I've attached a crude diff of all the fixes I have queued together, and there it works perfectly fine, but there's a lot of modifications required to properly traverse the words array. I've meant to create a special function to traverse this array, but I haven't had time time for that; I haven't even landed this patch due to apparently irrelevant discussions. Cheers. -- Felipe Contreras
Attachment:
fc-bash-update.diff
Description: Binary data