sdk.plugin.zsh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env zsh
  2. ### SDKMAN Autocomplete for Oh My Zsh
  3. _sdk() {
  4. case "${CURRENT}" in
  5. 2)
  6. compadd -X $'Commands:\n' -- "${${(Mk)functions[@]:#__sdk_*}[@]#__sdk_}"
  7. compadd -n rm
  8. ;;
  9. 3)
  10. case "${words[2]}" in
  11. l|ls|list|i|install)
  12. compadd -X $'Candidates:\n' -- "${SDKMAN_CANDIDATES[@]}"
  13. ;;
  14. ug|upgrade|h|home|c|current|u|use|d|default|rm|uninstall)
  15. compadd -X $'Installed Candidates:\n' -- "${${(u)${(f)$(find -L -- "${SDKMAN_CANDIDATES_DIR}" -mindepth 2 -maxdepth 2 -type d)}[@]:h}[@]:t}"
  16. ;;
  17. e|env)
  18. compadd init
  19. ;;
  20. offline)
  21. compadd enable disable
  22. ;;
  23. selfupdate)
  24. compadd force
  25. ;;
  26. flush)
  27. compadd archives broadcast temp version
  28. ;;
  29. esac
  30. ;;
  31. 4)
  32. case "${words[2]}" in
  33. i|install)
  34. setopt localoptions kshglob
  35. if [[ "${words[3]}" == 'java' ]]; then
  36. compadd -X $'Installable Versions of java:\n' -- "${${${${${(f)$(__sdkman_list_versions "${words[3]}")}[@]:5:-4}[@]:#* | (local only|installed ) | *}[@]##* | | }[@]%%+( )}"
  37. else
  38. compadd -X "Installable Versions of ${words[3]}:"$'\n' -- "${${(z)${(M)${(f)${$(__sdkman_list_versions "${words[3]}")//[*+>]+( )/-}}[@]:# *}[@]}[@]:#-*}"
  39. fi
  40. ;;
  41. h|home|u|use|d|default|rm|uninstall)
  42. 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}"
  43. ;;
  44. esac
  45. ;;
  46. 5)
  47. case "${words[2]}" in
  48. i|install)
  49. _files -X "Path to Local Installation of ${words[3]} ${words[4]}:"$'\n' -/
  50. ;;
  51. esac
  52. ;;
  53. esac
  54. }
  55. compdef _sdk sdk