From b054e25d25aacdde7c64b002147b6cebdd78d0d2 Mon Sep 17 00:00:00 2001 From: Rahul Somasunderam Date: Wed, 8 May 2019 01:27:05 -0700 Subject: [PATCH] Add plugin for SDKMAN (#6483) SDKMAN! is a tool for managing parallel versions of multiple Software Development Kits on most Unix based systems. --- plugins/sdk/README.md | 8 ++++ plugins/sdk/sdk.plugin.zsh | 82 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 plugins/sdk/README.md create mode 100644 plugins/sdk/sdk.plugin.zsh diff --git a/plugins/sdk/README.md b/plugins/sdk/README.md new file mode 100644 index 000000000..b237f3b4c --- /dev/null +++ b/plugins/sdk/README.md @@ -0,0 +1,8 @@ +# sdk + +Plugin for SDKMAN, a tool for managing parallel versions of multiple Software Development Kits on most Unix based systems. +Provides autocompletion for all known commands. + +## Requirements + + * [SDKMAN](http://sdkman.io/) diff --git a/plugins/sdk/sdk.plugin.zsh b/plugins/sdk/sdk.plugin.zsh new file mode 100644 index 000000000..d00459b16 --- /dev/null +++ b/plugins/sdk/sdk.plugin.zsh @@ -0,0 +1,82 @@ +### SDKMAN Autocomplete for Oh My Zsh + +# This is the output from sdkman. All the these options are supported at the +# moment. + +# Usage: sdk [candidate] [version] +# sdk offline +# +# commands: +# install or i [version] +# uninstall or rm +# list or ls [candidate] +# use or u [version] +# default or d [version] +# current or c [candidate] +# upgrade or ug [candidate] +# version or v +# broadcast or b +# help or h +# offline [enable|disable] +# selfupdate [force] +# update +# flush +# +# candidate : the SDK to install: groovy, scala, grails, gradle, kotlin, etc. +# use list command for comprehensive list of candidates +# eg: $ sdk list +# +# version : where optional, defaults to latest stable if not provided +# eg: $ sdk install groovy + +local _sdk_commands=( + install i + uninstall rm + list ls + use u + default d + current c + upgrade ug + version v + broadcast b + help h + offline + selfupdate + update + flush +) + +_listInstalledVersions() { + __sdkman_build_version_csv $1 | sed -e "s/,/ /g" +} + +_listInstallableVersions() { + __sdkman_list_versions $1 | grep "^ " | sed -e "s/\* /*/g" | \ + sed -e "s/>//g" | xargs -n 1 echo | grep -v "^*" +} + +_listAllVersion() { + __sdkman_list_versions $1 | grep "^ " | sed -e "s/\*/ /g" | sed -e "s/>//g" +} + +_sdk () { + case $CURRENT in + 2) compadd -- $_sdk_commands ;; + 3) case "$words[2]" in + i|install|rm|uninstall|ls|list|u|use|d|default|c|current|ug|upgrade) + compadd -- $SDKMAN_CANDIDATES ;; + offline) compadd -- enable disable ;; + selfupdate) compadd -- force ;; + flush) compadd -- candidates broadcast archives temp ;; + esac + ;; + 4) case "$words[2]" in + rm|uninstall|d|default) compadd -- $(_listInstalledVersions $words[3]) ;; + i|install) compadd -- $(_listInstallableVersions $words[3]) ;; + u|use) compadd -- $(_listAllVersion $words[3]) ;; + esac + ;; + esac +} + +compdef _sdk sdk