From d59e0c397a174babbeed7867a0561394d1c8afdd Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 18 Mar 2015 01:17:01 -0300 Subject: [PATCH] zsh completions and refactory --- jvm.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/jvm.sh b/jvm.sh index 448c688..6165c51 100755 --- a/jvm.sh +++ b/jvm.sh @@ -48,6 +48,10 @@ EOF $EDITOR ~/.jvmconfig } +_jvm-command-list() { + echo "local global version reload config" +} + jvm() { if [ "$#" != 0 ]; then local command="$1"; shift @@ -71,7 +75,7 @@ jvm() { _jvm-edit-config ;; *) - echo "Usage: jvm (local|global|version|reload|config) " + echo "Usage: jvm (${$(_jvm-command-list)// /|}) " return 0 ;; esac @@ -81,11 +85,16 @@ main() { _jvm-discover-and-set-version if [ ! -z "$BASH" ]; then PROMPT_COMMAND=_jvm-discover-and-set-version - complete -W "local global version reload config" jvm + complete -W "$(_jvm-command-list)" jvm elif [ ! -z "$ZSH_NAME" ]; then chpwd() { _jvm-discover-and-set-version } + _jvm-completions() { + # shellcheck disable=SC2039 + IFS=' ' read -A reply <<< "$(_jvm-command-list)" + } + compctl -K _jvm-completions jvm fi }