Good idea splitting out the exclude list, but as it is currently posted there are some problems with that.
First, the exclude list is declared local to the shell function, but is only used outside the function. Of course, when used outside the function, it expands to nothing, which is broken.
Secondly, there appear to be some quoting problems with the exclude list too, because even with the exclude string moved outside the function, it still doesn't actually work as posted. When in my source tree I do
I'm still seeing my object files (*.o) along with my source files.
Third, I get an awk error when use the -t flag but try to complete a filename. I realize this is not the intended use of the -t flag, but it happens and it's bad form to let it crash the completion command. I totally missed this in my earlier post.
Here's an updated version which fixes all the above issues:
Code:
_vim_ctags() {
local cur prev
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
case "${prev}" in
-t)
# Avoid the complaint message when no tags file exists
if [ ! -r ./tags ]
then
return
fi
# Escape slashes to avoid confusing awk
# (eg. without this, if $cur contains slashes (eg. "./dir/path"), the awk command /^${cur}/
# could expand to /^./dir/path/, which is a syntax error.)
# For an explanation of this command: man bash | less -p 'Parameter Expansion'
cur=${cur////\\/}
COMPREPLY=( $(compgen -W "`awk -vORS=" " "/^${cur}/ { print \\$1 }" tags`" ) )
;;
*)
_filedir_xspec
;;
esac
}
# Files matching this pattern are excluded
excludelist='*.@(o|O|so|SO|so.!(conf)|SO.!(CONF)|a|A|rpm|RPM|deb|DEB|gif|GIF|jp?(e)g|JP?(E)G|mp3|MP3|mp?(e)g|MP?(E)G|avi|AVI|asf|ASF|ogg|OGG|class|CLASS)'
complete -F _vim_ctags -f -X "${excludelist}" vi vim gvim rvim view rview rgvim rgview gview
Bookmarks