rtx.plugin.zsh 888 B

123456789101112131415161718192021222324252627282930
  1. # Find where rtx should be installed
  2. RTX_DIR="${RTX_DIR:-$HOME/.rtx}"
  3. RTX_COMPLETIONS="$RTX_DIR/completions"
  4. if [[ ! -f "$RTX_DIR/rtx.sh" || ! -f "$RTX_COMPLETIONS/_rtx" ]]; then
  5. # If not found, check for archlinux/AUR package (/opt/rtx-vm/)
  6. if [[ -f "/opt/rtx-vm/rtx.sh" ]]; then
  7. RTX_DIR="/opt/rtx-vm"
  8. RTX_COMPLETIONS="$RTX_DIR"
  9. # If not found, check for Homebrew package
  10. elif (( $+commands[brew] )); then
  11. _RTX_PREFIX="$(brew --prefix rtx)"
  12. RTX_DIR="${_RTX_PREFIX}/libexec"
  13. RTX_COMPLETIONS="${_RTX_PREFIX}/share/zsh/site-functions"
  14. unset _RTX_PREFIX
  15. else
  16. return
  17. fi
  18. fi
  19. # Load command
  20. if [[ -f "$RTX_DIR/rtx.sh" ]]; then
  21. source "$RTX_DIR/rtx.sh"
  22. # Load completions
  23. if [[ -f "$RTX_COMPLETIONS/_rtx" ]]; then
  24. fpath+=("$RTX_COMPLETIONS")
  25. autoload -Uz _rtx
  26. compdef _rtx rtx # compdef is already loaded before loading plugins
  27. fi
  28. fi