30a8a5d3e2f36e395c439c3346ef96e40e7bd277
- Author
- Marc Cornellà <hello@mcornella.com>
- Committer
- GitHub <noreply@github.com>
- Date
Message
fix(rtx): fix `rtx` init procedure (#11949)
Diff
1diff --git a/plugins/rtx/rtx.plugin.zsh b/plugins/rtx/rtx.plugin.zsh
2index aaccaf01532f5332189ccff2f552c4aa96f741c2..a01828afd48eb5337c4d228a0307e531af2e7e17 100644
3--- a/plugins/rtx/rtx.plugin.zsh
4+++ b/plugins/rtx/rtx.plugin.zsh
5@@ -1,30 +1,18 @@
6-# Find where rtx should be installed
7-RTX_DIR="${RTX_DIR:-$HOME/.rtx}"
8-RTX_COMPLETIONS="$RTX_DIR/completions"
9-
10-if [[ ! -f "$RTX_DIR/rtx.sh" || ! -f "$RTX_COMPLETIONS/_rtx" ]]; then
11- # If not found, check for archlinux/AUR package (/opt/rtx-vm/)
12- if [[ -f "/opt/rtx-vm/rtx.sh" ]]; then
13- RTX_DIR="/opt/rtx-vm"
14- RTX_COMPLETIONS="$RTX_DIR"
15- # If not found, check for Homebrew package
16- elif (( $+commands[brew] )); then
17- _RTX_PREFIX="$(brew --prefix rtx)"
18- RTX_DIR="${_RTX_PREFIX}/libexec"
19- RTX_COMPLETIONS="${_RTX_PREFIX}/share/zsh/site-functions"
20- unset _RTX_PREFIX
21- else
22- return
23- fi
24+# rtx needs to be in $PATH
25+if (( ! ${+commands[rtx]} )); then
26+ return
27 fi
28
29-# Load command
30-if [[ -f "$RTX_DIR/rtx.sh" ]]; then
31- source "$RTX_DIR/rtx.sh"
32- # Load completions
33- if [[ -f "$RTX_COMPLETIONS/_rtx" ]]; then
34- fpath+=("$RTX_COMPLETIONS")
35- autoload -Uz _rtx
36- compdef _rtx rtx # compdef is already loaded before loading plugins
37- fi
38+# Load rtx hooks
39+eval "$(rtx activate zsh)"
40+
41+# If the completion file doesn't exist yet, we need to autoload it and
42+# bind it to `rtx`. Otherwise, compinit will have already done that.
43+if [[ ! -f "$ZSH_CACHE_DIR/completions/_rtx" ]]; then
44+ typeset -g -A _comps
45+ autoload -Uz _rtx
46+ _comps[rtx]=_rtx
47 fi
48+
49+# Generate and load rtx completion
50+rtx completion zsh >! "$ZSH_CACHE_DIR/completions/_rtx" &|