chshersh / tool-sync

🧰 Download pre-built binaries of all your favourite tools with a single command
https://crates.io/crates/tool-sync
Mozilla Public License 2.0
69 stars 16 forks source link

Bash autocompletion doesn't work #159

Open chshersh opened 1 year ago

chshersh commented 1 year ago

I'm trying to configure autocompletion for tool-sync. Unfortunately, it doesn't work on my Ubuntu 20.04 and bash shell. I'm trying to add the suggested line to .bashrc and ~/.bash_profile (I also made sure that I have bash-completion installed).

I tried specifying the following lines. But nothing works for me:

eval "$(tool completion bash)"
eval "$(tool completion bash --rename tool)"
`eval "$(tool completion bash)"`
`eval "$(tool completion bash --rename tool)"`
source <(tool completion bash)
source <(tool completion bash --rename tool)

So some investigation is required to fix this. Maybe it's just me. I'll have a look at the completion package and see if anything needs to be done or how to make it work.

On top of that, I can see, this probably happens because by default, the tool completion command uses the tool-sync name.

complete -F _tool-sync -o bashdefault -o default tool-sync

It would be great if tool was used by default (maybe there's a way to do this in the autocompletion package we use?). Otherwise, documentation should change to always suggest the --rename flag.

MitchellBerend commented 1 year ago

I can take a look at this when I get home. I also recently found out using an aliased command keeps the autocomplete working like the original command, so maybe its a good idea to remove the rename flag if that is the source of the issue.

MitchellBerend commented 1 year ago

complete -F _tool-sync -o bashdefault -o default tool-sync

Took a quick look at this, it seems the get_name command takes the name from the Cargo.toml.

This change image

Produces this print out

...
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
    esac
}

complete -F _alskdjhfasdkjlfh -o bashdefault -o default alskdjhfasdkjlfh
MitchellBerend commented 1 year ago
$ lsb_release
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04 LTS
Release:    22.04
Codename:   jammy

This is in my .bashrc

eval "$(tool-sync completion bash --rename tool-sync 2> /dev/null)"

This works on both my ubuntu machines. The std err needs to be redirected since it will print the instructions on start up. This is also something that needs to be fixed.

As for the name that gets used when the rename flag is not passed, its currently using the name defined in the Cargo.toml but it can of course be hard coded by using a constant in the src/lib.rs instead of calling the get_name method.

MitchellBerend commented 1 year ago

@chshersh are you still experiencing problems?