1 # bash/zsh completion support for OPNFV Apex
2 ##############################################################################
3 # Copyright (c) 2016 Dan Radez (Red Hat) and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
11 # Pieces of this script are derived from the git bash completion script
16 cur="${COMP_WORDS[COMP_CWORD]}"
17 prev="${COMP_WORDS[COMP_CWORD-1]}"
18 opts=" -h $(${COMP_WORDS[0]} -h | grep -Eo '^ [^ ]+')"
19 if [[ ! $opts =~ $prev ]]; then
20 COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
24 # these functions are setup like this in the thought that
25 # deploy and util will eventually diverge from each other
26 # for now they can use the same main logic so it's just
27 # abstracted to another function
39 local cur words cword prev
40 _get_comp_words_by_ref -n =: cur words cword prev
44 # Setup function for bash completion
46 local wrapper="__apex_wrap${2}"
47 eval "$wrapper () { __apex_func_wrap $2 ; }"
48 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
49 || complete -o default -o nospace -F $wrapper $1
52 # run completion setup
53 __apex_complete ./deploy.py __deploy_main
54 __apex_complete opnfv-deploy __deploy_main
55 __apex_complete ./util.sh __util_main
56 __apex_complete opnfv-util __util_main