JoshMcguigan / shell_completion

Write shell completion scripts in pure Rust
Apache License 2.0
133 stars 6 forks source link

Can't get the example to work as intended #8

Closed itacud95 closed 1 year ago

itacud95 commented 1 year ago

I am having issues running the example from the documentation.

Here is my chain of commands:

git clone git@github.com:JoshMcguigan/shell_completion.git
cd shell_completion/
$ cargo install --force --path cargo_completion/ && complete -C _cargo_completion cargo
  Installing cargo_completion v0.0.1 (/home/jk/dev/rust/shell_completion/cargo_completion)
   Compiling shell_completion v0.0.1 (/home/jk/dev/rust/shell_completion/shell_completion)
   Compiling cargo_completion v0.0.1 (/home/jk/dev/rust/shell_completion/cargo_completion)
    Finished release [optimized] target(s) in 2.64s
  Installing /home/jk/.cargo/bin/_cargo_completion
   Installed package `cargo_completion v0.0.1 (/home/jk/dev/rust/shell_completion/cargo_completion)` (executable `_cargo_completion`)

Now, running it with cargo run --<tab> does not work as intended:

cargo run --bash: _cargo_completion: command not found
bash: _cargo_completion: command not found
bash: _cargo_completion: command not found
bash: _cargo_completion: command not found
^C

What am I doing wrong?

JoshMcguigan commented 1 year ago
  Installing /home/jk/.cargo/bin/_cargo_completion
  ...
  bash: _cargo_completion: command not found

I'm guessing /home/jk/.cargo/bin is not on your $PATH. You can either add it, or perhaps (I haven't tested this, but I don't see why it wouldn't work) modify the complete -C _cargo_completion cargo setup to provide the full path to _cargo_completion, as in complete -C /home/jk/.cargo/bin/_cargo_completion cargo.

itacud95 commented 1 year ago

Yes, you are right!

This returns nothing: echo $PATH | grep .cargo

And your command works as expected:

complete -C /home/jk/.cargo/bin/_cargo_completion cargo
cargo run --
--all-features         --example              --help                 --manifest-path        --package              --target               
--bin                  --features             --jobs                 --message-format       --quiet                --target-dir           
--color                --frozen               --locked               --no-default-features  --release              --verbose