Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
Ohmyzsh
Commits
373e27d8
Unverified
Commit
373e27d8
authored
Apr 30, 2020
by
Ross Goldberg
Committed by
GitHub
Apr 30, 2020
Browse files
sdk: improve sdkman completion (#8854)
parent
c686aa3d
Changes
1
Hide whitespace changes
Inline
Side-by-side
plugins/sdk/sdk.plugin.zsh
View file @
373e27d8
### SDKMAN Autocomplete for Oh My Zsh
#!/usr/bin/env zsh
# This is the output from sdkman. All the these options are supported at the
# moment.
# Usage: sdk <command> [candidate] [version]
# sdk offline <enable|disable>
#
# commands:
# install or i <candidate> [version] [local-path]
# uninstall or rm <candidate> <version>
# list or ls [candidate]
# use or u <candidate> <version>
# default or d <candidate> [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 <broadcast|archives|temp>
#
# 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-path : optional path to an existing local installation
# eg: $ sdk install groovy 2.4.13-local /opt/groovy-2.4.13
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
()
{
# Remove local (+) and installed (*) versions from the list
__sdkman_list_versions
$1
|
sed
-e
'/^[^ ]/d;s/[+*] [^ ]\+//g;s/>//g'
}
_listAllVersion
()
{
### SDKMAN Autocomplete for Oh My Zsh
# Remove (*), (+), and (>) characters from the list
__sdkman_list_versions
$1
|
sed
-e
'/^[^ ]/d;s/[*+>] //g'
}
_sdk
()
{
_sdk
()
{
case
$CURRENT
in
case
"
${
CURRENT
}
"
in
2
)
compadd
--
$_sdk_commands
;;
2
)
3
)
case
"
$words
[2]"
in
compadd
-X
$'Commands:
\n
'
--
"
${${
(Mk)functions[@]
:#__sdk_
*
}
[@]#__sdk_
}
"
i|install|rm|uninstall|ls|list|u|use|d|default|c|current|ug|upgrade
)
compadd
-n
rm
compadd
--
$SDKMAN_CANDIDATES
;;
;;
offline
)
compadd
--
enable
disable
;;
3
)
selfupdate
)
compadd
--
force
;;
case
"
${
words
[2]
}
"
in
flush
)
compadd
--
broadcast archives temp
;;
l|ls|list|i|install
)
esac
compadd
-X
$'Candidates:
\n
'
--
"
${
SDKMAN_CANDIDATES
[@]
}
"
;;
;;
4
)
case
"
$words
[2]"
in
ug|upgrade|c|current|u|use|d|default|rm|uninstall
)
rm
|
uninstall|d|default
)
compadd
--
$(
_listInstalledVersions
$words
[
3]
)
;;
compadd
-X
$'Installed Candidates:
\n
'
--
"
${${
(u)
${
(f)
$(
find
-L
--
"
${
SDKMAN_CANDIDATES_DIR
}
"
-mindepth
2
-maxdepth
2
-type
d
)
}
[@]
:h
}
[@]
:t
}
"
i|install
)
compadd
--
$(
_listInstallableVersions
$words
[
3]
)
;;
;;
u|use
)
compadd
--
$(
_listAllVersion
$words
[
3]
)
;;
offline
)
esac
compadd
enable
disable
;;
;;
esac
selfupdate
)
compadd force
;;
flush
)
compadd archives broadcast temp version
;;
esac
;;
4
)
case
"
${
words
[2]
}
"
in
i|install
)
setopt localoptions kshglob
if
[[
"
${
words
[3]
}
"
==
'java'
]]
;
then
compadd
-X
$'Installable Versions of java:
\n
'
--
"
${${${${${
(f)
$(
__sdkman_list_versions
"
${
words
[3]
}
"
)
}
[@]
:5:-4
}
[@]
:#
* | (local only|installed ) | *
}
[@]##* | |
}
[@]%%+( )
}
"
else
compadd
-X
"Installable Versions of
${
words
[3]
}
:"
$'
\n
'
--
"
${${
(z)
${
(M)
${
(f)
${
$(
__sdkman_list_versions
"
${
words
[3]
}
"
)
//[*+>]+( )/-
}}
[@]
:#
*
}
[@]
}
[@]
:#-
*
}
"
fi
;;
u|use|d|default|rm|uninstall
)
compadd
-X
"Installed Versions of
${
words
[3]
}
:"
$'
\n
'
--
"
${${
(f)
$(
find
-L
--
"
${
SDKMAN_CANDIDATES_DIR
}
/
${
words
[3]
}
"
-mindepth
1
-maxdepth
1
-type
d
-not
-name
'current'
)
}
[@]
:t
}
"
;;
esac
;;
5
)
case
"
${
words
[2]
}
"
in
i|install
)
_files
-X
"Path to Local Installation of
${
words
[3]
}
${
words
[4]
}
:"
$'
\n
'
-/
;;
esac
;;
esac
}
}
compdef _sdk sdk
compdef _sdk sdk
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment