diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2012-10-09 10:27:50 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2012-10-09 10:27:50 +0200 |
commit | 99e234b8c020f9cbb9a6e5e1a57efc865e60043c (patch) | |
tree | f81901473d7f23dab1bcace92c761cd35640247c | |
parent | d61e10d1c9754e292511404a6d3ed02ce071080e (diff) | |
download | app.sh-99e234b8c020f9cbb9a6e5e1a57efc865e60043c.tar.gz app.sh-99e234b8c020f9cbb9a6e5e1a57efc865e60043c.tar.bz2 app.sh-99e234b8c020f9cbb9a6e5e1a57efc865e60043c.tar.xz app.sh-99e234b8c020f9cbb9a6e5e1a57efc865e60043c.zip |
o Basic completion for app.sh.
-rw-r--r-- | app_completion | 43 |
1 files changed, 43 insertions, 0 deletions
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 |