From 99e234b8c020f9cbb9a6e5e1a57efc865e60043c Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Tue, 9 Oct 2012 10:27:50 +0200 Subject: o Basic completion for app.sh. --- app_completion | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 app_completion diff --git a/app_completion b/app_completion new file mode 100644 index 0000000..883b609 --- /dev/null +++ b/app_completion @@ -0,0 +1,43 @@ +#!/bin/bash + +_find_name() { + local prev="" + for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do + if [ "$prev" == -n ] + then + echo "${COMP_WORDS[$i]}" + fi + prev="${COMP_WORDS[$i]}" + done +} + +_complete_appsh_name() { +# set -x + COMPREPLY=() + local cur="${COMP_WORDS[COMP_CWORD]}" + local prev="${COMP_WORDS[COMP_CWORD-1]}" + local opts="-n -i" + local name + + case $prev in + -n) + values=$(./app list -P name) + COMPREPLY=( $(compgen -W "$values" -- ${cur}) ) + return 0 + ;; + -i) + name=`_find_name` + if [ -n "$name" ] + then + values=$(./app list -n $name -P instance) + COMPREPLY=( $(compgen -W "$values" -- ${cur}) ) + return 0 + fi + ;; + esac + + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + set +x +} + +complete -F _complete_appsh_name app -- cgit v1.2.3