mise.zsh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Source it
  2. eval "$($HOME/.local/bin/mise activate zsh)"
  3. # Install mise if not present (with caching to avoid repeated checks)
  4. if ! command -v mise &> /dev/null && [[ ! -f ~/.local/bin/mise ]]; then
  5. echo "Installing mise..."
  6. mkdir -p ~/.local/bin
  7. curl https://mise.jdx.dev/mise-latest-linux-x64 > ~/.local/bin/mise
  8. chmod +x ~/.local/bin/mise
  9. ~/.local/bin/mise install
  10. fi
  11. #compdef mise
  12. local curcontext="$curcontext"
  13. # caching config
  14. _usage_mise_cache_policy() {
  15. if [[ -z "${lifetime}" ]]; then
  16. lifetime=$((60*60*4)) # 4 hours
  17. fi
  18. local -a oldp
  19. oldp=( "$1"(Nms+${lifetime}) )
  20. (( $#oldp ))
  21. }
  22. _mise() {
  23. typeset -A opt_args
  24. local curcontext="$curcontext" spec cache_policy
  25. if ! command -v usage &> /dev/null; then
  26. echo >&2
  27. echo "Error: usage CLI not found. This is required for completions to work in mise." >&2
  28. echo "See https://usage.jdx.dev for more information." >&2
  29. return 1
  30. fi
  31. zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
  32. if [[ -z $cache_policy ]]; then
  33. zstyle ":completion:${curcontext}:" cache-policy _usage_mise_cache_policy
  34. fi
  35. if ( [[ -z "${_usage_mise_spec:-}" ]] || _cache_invalid _usage_mise_spec ) \
  36. && ! _retrieve_cache _usage_mise_spec;
  37. then
  38. spec="$(mise usage)"
  39. _store_cache _usage_mise_spec spec
  40. fi
  41. _arguments "*: :(($(usage complete-word --shell zsh -s "$spec" -- "${words[@]}" )))"
  42. return 0
  43. }
  44. if [ "$funcstack[1]" = "_mise" ]; then
  45. _mise "$@"
  46. else
  47. compdef _mise mise
  48. fi