summaryrefslogtreecommitdiff
path: root/app_completion
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-10-09 11:07:21 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2012-10-09 11:07:42 +0200
commit6bf1f04bfe49ae0a178d5f342faf424b519939a3 (patch)
treef2c5a33b6acb46819b3731082f34b825b11b8640 /app_completion
parent99e234b8c020f9cbb9a6e5e1a57efc865e60043c (diff)
downloadapp.sh-6bf1f04bfe49ae0a178d5f342faf424b519939a3.tar.gz
app.sh-6bf1f04bfe49ae0a178d5f342faf424b519939a3.tar.bz2
app.sh-6bf1f04bfe49ae0a178d5f342faf424b519939a3.tar.xz
app.sh-6bf1f04bfe49ae0a178d5f342faf424b519939a3.zip
o Smarter $opts.
Diffstat (limited to 'app_completion')
-rw-r--r--app_completion32
1 files changed, 22 insertions, 10 deletions
diff --git a/app_completion b/app_completion
index 883b609..3fa10c9 100644
--- a/app_completion
+++ b/app_completion
@@ -1,23 +1,25 @@
#!/bin/bash
-_find_name() {
+_appsh_parse_opts() {
local prev=""
for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
if [ "$prev" == -n ]
then
- echo "${COMP_WORDS[$i]}"
+ echo "local has_n=${COMP_WORDS[$i]}"
+ elif [ "$prev" == -i ]
+ then
+ echo "local has_i=${COMP_WORDS[$i]}"
fi
prev="${COMP_WORDS[$i]}"
done
}
-_complete_appsh_name() {
-# set -x
+_complete_appsh() {
COMPREPLY=()
local cur="${COMP_WORDS[COMP_CWORD]}"
local prev="${COMP_WORDS[COMP_CWORD-1]}"
- local opts="-n -i"
- local name
+
+ eval `_appsh_parse_opts`
case $prev in
-n)
@@ -26,18 +28,28 @@ _complete_appsh_name() {
return 0
;;
-i)
- name=`_find_name`
- if [ -n "$name" ]
+ if [ -n "$has_n" ]
then
- values=$(./app list -n $name -P instance)
+ values=$(./app list -n $has_n -P instance)
COMPREPLY=( $(compgen -W "$values" -- ${cur}) )
return 0
fi
;;
esac
+ opts=""
+ if [ -z "$has_n" ]
+ then
+ opts="$opts -n"
+ else
+ if [ -z "$has_i" ]
+ then
+ opts="$opts -i"
+ fi
+ fi
+
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
set +x
}
-complete -F _complete_appsh_name app
+complete -F _complete_appsh app