diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2012-10-16 23:57:41 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2012-10-16 23:57:41 +0200 |
commit | a3ce3f7eabbb746aa9ced430bcd55391742c738b (patch) | |
tree | e4dcab1586b725508a57bfce83f3067a95b26a89 /app_completion | |
parent | f563dc165ce1ee8747eea647231bf8e295d8af3f (diff) | |
download | app.sh-a3ce3f7eabbb746aa9ced430bcd55391742c738b.tar.gz app.sh-a3ce3f7eabbb746aa9ced430bcd55391742c738b.tar.bz2 app.sh-a3ce3f7eabbb746aa9ced430bcd55391742c738b.tar.xz app.sh-a3ce3f7eabbb746aa9ced430bcd55391742c738b.zip |
o Improved completion (again).
o Consistent usage of APPSH_HOME and BASEDIR.
Diffstat (limited to 'app_completion')
-rw-r--r-- | app_completion | 56 |
1 files changed, 45 insertions, 11 deletions
diff --git a/app_completion b/app_completion index c4bfe02..fd25f66 100644 --- a/app_completion +++ b/app_completion @@ -1,16 +1,25 @@ #!/bin/bash -_appsh_contains() { +_appsh_find() { local e for e in "${@:2}"; do [[ "$e" == "$1" ]] && echo $1 && return; done } -_appsh_methods=( +_appsh_method_groups=( "instance" "conf" "operate" ) +_appsh_methods=( + "install" + ) + +_appsh_resolvers=( + "file" + "maven" + ) + _appsh_parse_opts() { local prev="" local has_method @@ -24,9 +33,11 @@ _appsh_parse_opts() { echo "local has_i=$curr" fi - has_method="$has_method$(_appsh_contains "$curr" ${_appsh_methods[@]})" + has_method_group="$has_method_group$(_appsh_find "$curr" ${_appsh_method_groups[@]})" + has_method="$has_method$(_appsh_find "$curr" ${_appsh_methods[@]})" prev="${COMP_WORDS[$i]}" done + echo "local has_method_group='$has_method_group'" echo "local has_method='$has_method'" case "${COMP_WORDS[COMP_CWORD]}" in @@ -42,11 +53,13 @@ _complete_appsh() { local prev="${COMP_WORDS[COMP_CWORD-1]}" local opts="" - eval `_appsh_parse_opts` + local x=`_appsh_parse_opts` + eval "$x" +# set | grep ^has_ if [ $COMP_CWORD == 1 ] then - opts="${_appsh_methods[@]}" + opts="${_appsh_method_groups[@]}" opts="$opts" if [ "$in_option" = "yes" ] then @@ -56,7 +69,7 @@ _complete_appsh() { return 0 fi - case $prev in + case "$prev" in -n) values=$(./app instance list -P name) COMPREPLY=($(compgen -W "$values" -- ${cur})) @@ -70,6 +83,15 @@ _complete_appsh() { return 0 fi ;; + -r) + COMPREPLY="${_appsh_resolvers[@]}" + COMPREPLY=($(compgen -W "$COMPREPLY" -- ${cur})) + return + ;; + -u) + COMPREPLY=($(compgen -f -- ${cur})) + return + ;; esac if [ -n "$has_n" -a -z "$has_i" ] @@ -77,13 +99,25 @@ _complete_appsh() { opts="$opts -i" fi - if [ -z "$has_method" ] - then - opts="$opts ${_appsh_methods[@]}" - fi + has_method_group=$has_method_group + has_method=$has_method + case "$has_method_group" in + instance) + if [ -z $has_method ] + then + opts="$opts install list list-versions set-current" + else + case "$has_method" in + install) + opts="$opts -r -u" + ;; + esac + fi + ;; + esac COMPREPLY=($(compgen -W "${opts}" -- ${cur})) set +x } -complete -F _complete_appsh app +complete -d -F _complete_appsh app |