summaryrefslogtreecommitdiffstats
path: root/build/bash_completion_apex
diff options
context:
space:
mode:
authorDan Radez <dradez@redhat.com>2016-09-16 14:26:59 -0400
committerDan Radez <dradez@redhat.com>2016-09-19 07:54:54 -0400
commit40591ae2096020c0eba2af039c88715d8fdcf88a (patch)
treed5ad1661da0ce2bdd060f379b7f9bad00a720b62 /build/bash_completion_apex
parent1be5540878ac141d77fb570a63847578cdcf09d9 (diff)
Adding a bash completion script
- allows tab completion for deploy and clean script's subcommands Change-Id: If5f5718a3695993767671ab823f434f463c593f2 Signed-off-by: Dan Radez <dradez@redhat.com>
Diffstat (limited to 'build/bash_completion_apex')
-rw-r--r--build/bash_completion_apex56
1 files changed, 56 insertions, 0 deletions
diff --git a/build/bash_completion_apex b/build/bash_completion_apex
new file mode 100644
index 00000000..b3c963e3
--- /dev/null
+++ b/build/bash_completion_apex
@@ -0,0 +1,56 @@
+# bash/zsh completion support for OPNFV Apex
+##############################################################################
+# Copyright (c) 2016 Dan Radez (Red Hat) and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+# Pieces of this script are derived from the git bash completion script
+
+___main () {
+ local cur prev opts
+ COMPREPLY=()
+ cur="${COMP_WORDS[COMP_CWORD]}"
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
+ opts=" -h $(${COMP_WORDS[0]} -h | grep -Eo '^ [^ ]+')"
+ if [[ ! $opts =~ $prev ]]; then
+ COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
+ fi
+}
+
+# these functions are setup like this in the thought that
+# deploy and util will eventually diverge from each other
+# for now they can use the same main logic so it's just
+# abstracted to another function
+__deploy_main () {
+ ___main
+}
+
+
+__util_main () {
+ ___main
+}
+
+
+__apex_func_wrap () {
+ local cur words cword prev
+ _get_comp_words_by_ref -n =: cur words cword prev
+ $1
+}
+
+# Setup function for bash completion
+__apex_complete () {
+ local wrapper="__apex_wrap${2}"
+ eval "$wrapper () { __apex_func_wrap $2 ; }"
+ complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
+ || complete -o default -o nospace -F $wrapper $1
+}
+
+# run completion setup
+__apex_complete ./deploy.sh __deploy_main
+__apex_complete opnfv-deploy __deploy_main
+__apex_complete ./util.sh __util_main
+__apex_complete opnfv-util __util_main