Created
December 20, 2012 13:01
-
-
Save ramn/4345194 to your computer and use it in GitHub Desktop.
Generate tab completions for shell command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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