Diff
1diff --git a/plugins/cargo/README.md b/plugins/cargo/README.md
2index 31bae4efe084778fab262b135fe67325e5815df1..93e69ae7fad2ace0e8d1ba940e049ffa8539cc85 100644
3--- a/plugins/cargo/README.md
4+++ b/plugins/cargo/README.md
5@@ -1,11 +1,3 @@
6 # cargo
7
8-This plugin adds completion for the Rust build tool [`Cargo`](https://github.com/rust-lang/cargo).
9-
10-To use it, add `cargo` to the plugins array in your zshrc file:
11-
12-```zsh
13-plugins=(... cargo)
14-```
15-
16-Updated on March 3rd, 2019, from [Cargo 0.34.0](https://github.com/rust-lang/cargo/releases/tag/0.34.0).
17+**Deprecated: use the [`rust`](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/rust) plugin instead.**
18diff --git a/plugins/cargo/cargo.plugin.zsh b/plugins/cargo/cargo.plugin.zsh
19index 9d1d237576ff000b8712933183d0b78246c5c380..51a80d4f191ebca2d1c2c86148d85e4cd2592138 100644
20--- a/plugins/cargo/cargo.plugin.zsh
21+++ b/plugins/cargo/cargo.plugin.zsh
22@@ -1,24 +1,11 @@
23-if ! (( $+commands[rustup] && $+commands[cargo] )); then
24- return
25-fi
26+print ${(%):-'%F{yellow}The `cargo` plugin is deprecated and has been moved to the `rust` plugin.'}
27+print ${(%):-'Please update your .zshrc to use the `%Brust%b` plugin instead.%f'}
28
29 # Remove old generated completion file
30-# TODO: 2021-09-15: remove this line
31+# TODO: 2021-12-28: remove this line
32 command rm -f "${0:A:h}/_cargo"
33
34-# Add completions/ folder in $ZSH_CACHE_DIR
35-comp_file="$ZSH_CACHE_DIR/completions/_cargo"
36-command mkdir -p "${comp_file:h}"
37-(( ${fpath[(Ie)"$ZSH_CACHE_DIR/completions"]} )) || fpath=("$ZSH_CACHE_DIR/completions" $fpath)
38-
39-# If the completion file doesn't exist yet, we need to autoload it and
40-# bind it to `cargo`. Otherwise, compinit will have already done that
41-if [[ ! -f "$comp_file" ]]; then
42- autoload -Uz _cargo
43- declare -A _comps
44- _comps[cargo]=_cargo
45-fi
46-
47-# Generate completion file in the background
48-rustup completions zsh cargo >| "$comp_file" &|
49-unset comp_file
50+(( ${fpath[(Ie)$ZSH/plugins/rust]} )) || {
51+ fpath=("$ZSH/plugins/rust" $fpath)
52+ source "$ZSH/plugins/rust/rust.plugin.zsh"
53+}
54diff --git a/plugins/rust/README.md b/plugins/rust/README.md
55index 83d7d91ba23ac1ddd787165b72a2808c5fd70a26..e0536447461268866755e6f7079abe2ba24ec50a 100644
56--- a/plugins/rust/README.md
57+++ b/plugins/rust/README.md
58@@ -1,6 +1,6 @@
59 # rust
60
61-This plugin adds completion for [`rustc`](https://doc.rust-lang.org/rustc/index.html), the compiler for the Rust programming language.
62+This plugin adds completion for [`rustc`](https://doc.rust-lang.org/rustc/index.html), the compiler for the Rust programming language, as well as for `rustup` and `cargo` if you have the Rust toolchain installed.
63
64 To use it, add `rust` to the plugins array in your zshrc file:
65
66diff --git a/plugins/rust/_rust b/plugins/rust/_rustc
67rename from plugins/rust/_rust
68rename to plugins/rust/_rustc
69diff --git a/plugins/rust/rust.plugin.zsh b/plugins/rust/rust.plugin.zsh
70new file mode 100644
71index 0000000000000000000000000000000000000000..ced6eb4aaa82461275d8153db8c8fd64763355b0
72--- /dev/null
73+++ b/plugins/rust/rust.plugin.zsh
74@@ -0,0 +1,28 @@
75+if ! (( $+commands[rustup] && $+commands[cargo] )); then
76+ return
77+fi
78+
79+# Add completions folder in $ZSH_CACHE_DIR
80+# TODO: 2021-12-28: remove this bit of code as it exists in oh-my-zsh.sh
81+command mkdir -p "$ZSH_CACHE_DIR/completions"
82+(( ${fpath[(Ie)"$ZSH_CACHE_DIR/completions"]} )) || fpath=("$ZSH_CACHE_DIR/completions" $fpath)
83+
84+# If the completion file doesn't exist yet, we need to autoload it and
85+# bind it to `cargo`. Otherwise, compinit will have already done that
86+if [[ ! -f "$ZSH_CACHE_DIR/completions/_cargo" ]]; then
87+ autoload -Uz _cargo
88+ declare -A _comps
89+ _comps[cargo]=_cargo
90+fi
91+
92+# If the completion file doesn't exist yet, we need to autoload it and
93+# bind it to `rustup`. Otherwise, compinit will have already done that
94+if [[ ! -f "$ZSH_CACHE_DIR/completions/_rustup" ]]; then
95+ autoload -Uz _rustup
96+ declare -A _comps
97+ _comps[rustup]=_rustup
98+fi
99+
100+# Generate completion files in the background
101+rustup completions zsh >| "$ZSH_CACHE_DIR/completions/_rustup" &|
102+rustup completions zsh cargo >| "$ZSH_CACHE_DIR/completions/_cargo" &|
103diff --git a/plugins/rustup/README.md b/plugins/rustup/README.md
104index ba037f8f6885eb6c96922d2d78a09a2cd883481e..c620e72a853552c4cd25ad8093c2f1958ced915a 100644
105--- a/plugins/rustup/README.md
106+++ b/plugins/rustup/README.md
107@@ -1,9 +1,3 @@
108 # rustup
109
110-This plugin adds completion for [`rustup`](https://rustup.rs/), the toolchain installer for the Rust programming language.
111-
112-To use it, add `rustup` to the plugins array in your zshrc file:
113-
114-```zsh
115-plugins=(... rustup)
116-```
117+**Deprecated: use the [`rust`](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/rust) plugin instead.**
118diff --git a/plugins/rustup/rustup.plugin.zsh b/plugins/rustup/rustup.plugin.zsh
119index af8cf03a28b2e47d8dde551b3a743b7434443acc..0ca745b7e76a137b43ba3aa51a9a4787248b1653 100644
120--- a/plugins/rustup/rustup.plugin.zsh
121+++ b/plugins/rustup/rustup.plugin.zsh
122@@ -1,24 +1,11 @@
123-if (( ! $+commands[rustup] )); then
124- return
125-fi
126+print ${(%):-'%F{yellow}The `rustup` plugin is deprecated and has been moved to the `rust` plugin.'}
127+print ${(%):-'Please update your .zshrc to use the `%Brust%b` plugin instead.%f'}
128
129 # Remove old generated completion file
130-# TODO: 2021-09-15: remove this line
131+# TODO: 2021-12-28: remove this line
132 command rm -f "${0:A:h}/_rustup"
133
134-# Add completions/ folder in $ZSH_CACHE_DIR
135-comp_file="$ZSH_CACHE_DIR/completions/_rustup"
136-command mkdir -p "${comp_file:h}"
137-(( ${fpath[(Ie)"$ZSH_CACHE_DIR/completions"]} )) || fpath=("$ZSH_CACHE_DIR/completions" $fpath)
138-
139-# If the completion file doesn't exist yet, we need to autoload it and
140-# bind it to `rustup`. Otherwise, compinit will have already done that
141-if [[ ! -f "$comp_file" ]]; then
142- autoload -Uz _rustup
143- declare -A _comps
144- _comps[rustup]=_rustup
145-fi
146-
147-# Generate completion file in the background
148-rustup completions zsh >| "$comp_file" &|
149-unset comp_file
150+(( ${fpath[(Ie)$ZSH/plugins/rust]} )) || {
151+ fpath=("$ZSH/plugins/rust" $fpath)
152+ source "$ZSH/plugins/rust/rust.plugin.zsh"
153+}