New comment by ahesford on void-packages repository https://github.com/void-linux/void-packages/pull/35768#issuecomment-1190516788 Comment: I think we can make this work for zsh without conflicts. Leave the completions in the `cargo` package. In the `rustup` package, ship this file as `/usr/share/zsh/site-functions/_rustup_cargo`: ```sh #compdef cargo if command -v rustc >/dev/null 2>&1; then _rust_sysroot=$(rustc --print sysroot) if [ "$_rust_sysroot" != "/usr" ]; then _rust_cargo_comp="${_rust_sysroot}/share/zsh/site-functions/_cargo" [ -r "$_rust_cargo_comp" ] && source "$_rust_cargo_comp" unset _rust_cargo_comp fi unset _rust_sysroot fi ``` If `cargo` is installed, the system `/usr/share/zsh/site-functions/_cargo` file will be processed first. I believe zsh will ignore the definition in `_rustup_cargo` because it seems to pick only the first `#compdef cargo` definition. If `cargo` is not installed, this file will be processed and do the right thing for `rustup` users. As for bash, I don't really understand the completion system. Even with a custom script, I can't seem to get it to properly complete because the scripts seem to be sourced before the local environment defines the right path to `rustc`.