bash completion processing gone bad, how to debug?

It all started with a simple

alias gv='gvim --remote-quiet'

and now gv Space Tab gives nothing where it normally should give filenames. Oddly,

alias gvi='gvim --remote-quiet'

works as expected. I clearly have a workaround, but I'd like to know what is catching my gv for special processing. compopt is no help as gv shares the same settings as ls which does filename completion correctly.

$compopt gv
compopt +o bashdefault +o default +o dirnames -o filenames +o nospace +o plusdirs gv
$ compopt ls
compopt +o bashdefault +o default +o dirnames -o filenames +o nospace +o plusdirs ls

The complete command is slightly more helpful but it doesn't tell me why my two characters got singled out for alteration:

$ complete -p gv
complete -o filenames -F _filedir_xspec gv
$ complete -p ls
complete -o filenames -F _longopt ls
$ complete -p echo
bash: complete: echo: no completion specification
$ alias gvi='gvim --remote-silent'
$ complete -p gvi
bash: complete: gvi: no completion specification

Where did complete -o filenames -F _filedir_xpec gv come from?


Solution 1:

I got it, finally. It was hiding in /etc/bash_completions which - ironically - I overlooked as it didn't appear on my filename completions.

The helpful bash_completions thinks that gv means ghostview so it will only allow me to complete filenames that it expects ghostview can handle:

complete -f -X '!*.@(@(?(e)ps|?(E)PS|pdf|PDF)?' gv ggv kghostview

I think that counts as "too damn helpful". Adding

alias gv='gvim --remote-silent'
complete -r gv 

to my ~/.bash_aliases file was sufficient.