sdk.plugin.zsh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. ### SDKMAN Autocomplete for Oh My Zsh
  2. # This is the output from sdkman. All the these options are supported at the
  3. # moment.
  4. # Usage: sdk <command> [candidate] [version]
  5. # sdk offline <enable|disable>
  6. #
  7. # commands:
  8. # install or i <candidate> [version]
  9. # uninstall or rm <candidate> <version>
  10. # list or ls [candidate]
  11. # use or u <candidate> [version]
  12. # default or d <candidate> [version]
  13. # current or c [candidate]
  14. # upgrade or ug [candidate]
  15. # version or v
  16. # broadcast or b
  17. # help or h
  18. # offline [enable|disable]
  19. # selfupdate [force]
  20. # update
  21. # flush <candidates|broadcast|archives|temp>
  22. #
  23. # candidate : the SDK to install: groovy, scala, grails, gradle, kotlin, etc.
  24. # use list command for comprehensive list of candidates
  25. # eg: $ sdk list
  26. #
  27. # version : where optional, defaults to latest stable if not provided
  28. # eg: $ sdk install groovy
  29. local _sdk_commands=(
  30. install i
  31. uninstall rm
  32. list ls
  33. use u
  34. default d
  35. current c
  36. upgrade ug
  37. version v
  38. broadcast b
  39. help h
  40. offline
  41. selfupdate
  42. update
  43. flush
  44. )
  45. _listInstalledVersions() {
  46. __sdkman_build_version_csv $1 | sed -e "s/,/ /g"
  47. }
  48. _listInstallableVersions() {
  49. __sdkman_list_versions $1 | grep "^ " | sed -e "s/\* /*/g" | \
  50. sed -e "s/>//g" | xargs -n 1 echo | grep -v "^*"
  51. }
  52. _listAllVersion() {
  53. __sdkman_list_versions $1 | grep "^ " | sed -e "s/\*/ /g" | sed -e "s/>//g"
  54. }
  55. _sdk () {
  56. case $CURRENT in
  57. 2) compadd -- $_sdk_commands ;;
  58. 3) case "$words[2]" in
  59. i|install|rm|uninstall|ls|list|u|use|d|default|c|current|ug|upgrade)
  60. compadd -- $SDKMAN_CANDIDATES ;;
  61. offline) compadd -- enable disable ;;
  62. selfupdate) compadd -- force ;;
  63. flush) compadd -- candidates broadcast archives temp ;;
  64. esac
  65. ;;
  66. 4) case "$words[2]" in
  67. rm|uninstall|d|default) compadd -- $(_listInstalledVersions $words[3]) ;;
  68. i|install) compadd -- $(_listInstallableVersions $words[3]) ;;
  69. u|use) compadd -- $(_listAllVersion $words[3]) ;;
  70. esac
  71. ;;
  72. esac
  73. }
  74. compdef _sdk sdk