diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2012-10-10 12:54:05 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2012-10-10 12:54:30 +0200 |
commit | 908dd2b72e4ab4caa0bc77405d5636b935e0878e (patch) | |
tree | 21e6aa3873400c2ed72652327131e7ab186f5f26 | |
parent | 7a8c58e530cea4d2659ad1ef9a6288bbc8fd298c (diff) | |
download | app.sh-908dd2b72e4ab4caa0bc77405d5636b935e0878e.tar.gz app.sh-908dd2b72e4ab4caa0bc77405d5636b935e0878e.tar.bz2 app.sh-908dd2b72e4ab4caa0bc77405d5636b935e0878e.tar.xz app.sh-908dd2b72e4ab4caa0bc77405d5636b935e0878e.zip |
o Smarter completion of methods.
-rw-r--r-- | app_completion | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/app_completion b/app_completion index 0647c6d..62050fd 100644 --- a/app_completion +++ b/app_completion @@ -1,17 +1,37 @@ #!/bin/bash +_appsh_contains() { + local e + for e in "${@:2}"; do [[ "$e" == "$1" ]] && echo $1 && return; done +} + +_appsh_methods=( + "conf" + "install" + "list" + "list-versions" + "set-current" + "start" + "stop" + ) + _appsh_parse_opts() { local prev="" + local has_method for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do + local curr=${COMP_WORDS[$i]} if [ "$prev" == -n ] then - echo "local has_n=${COMP_WORDS[$i]}" + echo "local has_n=$curr" elif [ "$prev" == -i ] then - echo "local has_i=${COMP_WORDS[$i]}" + echo "local has_i=$curr" fi + + has_method="$has_method$(_appsh_contains "$curr" ${_appsh_methods[@]})" prev="${COMP_WORDS[$i]}" done + echo "local has_method='$has_method'" } _complete_appsh() { @@ -20,15 +40,16 @@ _complete_appsh() { local prev="${COMP_WORDS[COMP_CWORD-1]}" local opts + eval `_appsh_parse_opts` + if [ $COMP_CWORD == 1 ] then - opts="conf install list set-current start stop" + opts="${_appsh_methods[@]}" + opts="-n $opts" COMPREPLY=($(compgen -W "${opts}" -- ${cur})) return 0 fi - eval `_appsh_parse_opts` - case $prev in -n) values=$(./app list -P name) @@ -56,6 +77,11 @@ _complete_appsh() { fi fi + if [ -z "$has_method" ] + then + opts="$opts ${_appsh_methods[@]}" + fi + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) set +x } |