Skip to content

Instantly share code, notes, and snippets.

@ramn
Created December 20, 2012 13:01
Show Gist options
  • Save ramn/4345194 to your computer and use it in GitHub Desktop.
Save ramn/4345194 to your computer and use it in GitHub Desktop.
Generate tab completions for shell command
function _build_completions_helper {
local current_word
COMPREPLY=()
current_word=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=($(compgen -W "${PROGRAM_COMMANDS}" -- $current_word))
return 0
}
# param 1: command to build completions for. Ex: fab
#
# param 2: command that outputs all completable arguments for the app command
# (in param 1).
#
function _build_completions_for {
app=$1
command_list_call=$2
PROGRAM_COMMANDS=$($command_list_call)
complete -o nospace -F _build_completions_helper "$app"
}
# Example usage:
#_build_completions_for fab 'fab --shortlist'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment