Skip to content

Tab Completion

Keith Peters edited this page Sep 12, 2020 · 1 revision

Tab Completion

I did a bit of work to try to get tab completion working so that you'd be able to say, for example:

version p<TAB>

and it would show you all the tools it knows about that begin with p.

I had good results with bash on Linux. Create a file at /etc/bash_completion.d/_version with the following:

_version() 
{
  local cur prev opts
  COMPREPLY=()
  cur="${COMP_WORDS[COMP_CWORD]}"
  prev="${COMP_WORDS[COMP_CWORD-1]}"
  opts=$(version -l | tr -s "\n" " ")
  COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
  return 0
}
complete -F _version version

And tab completion should now work in bash. If you're using zsh, you might be able to get it working by doing the above and then adding the following lines to your .zshrc:

autoload -U +X compinit && compinit
autoload -U +X bashcompinit && bashcompinit
source /etc/bash_completion.d/_version

Macos is a lot more complicated and I haven't had much success there. Overall, I'm not sure this is worth the effort. You probably already know what command you are looking for the version of anyway. So I'll leave this here for you do to yourself.

Clone this wiki locally