liquidaty / zsv

zsv+lib: tabular data swiss-army knife CLI + world's fastest (simd) CSV parser
MIT License
202 stars 12 forks source link

Support shell command completion for Bash and other supported shells for better UX #152

Open iamazeem opened 7 months ago

iamazeem commented 7 months ago

Here's how minikube supports this as part of its binary:

$ minikube help completion 
Outputs minikube shell completion for the given shell (bash, zsh or fish)

    This depends on the bash-completion binary.  Example installation instructions:
    OS X:
        $ brew install bash-completion
        $ source $(brew --prefix)/etc/bash_completion
        $ minikube completion bash > ~/.minikube-completion  # for bash users
        $ minikube completion zsh > ~/.minikube-completion  # for zsh users
        $ source ~/.minikube-completion
        $ minikube completion fish > ~/.config/fish/completions/minikube.fish # for fish users
    Ubuntu:
        $ apt-get install bash-completion
        $ source /etc/bash-completion
        $ source <(minikube completion bash) # for bash users
        $ source <(minikube completion zsh) # for zsh users
        $ minikube completion fish > ~/.config/fish/completions/minikube.fish # for fish users

    Additionally, you may want to output the completion to a file and source in your .bashrc

    Note for zsh users: [1] zsh completions are only supported in versions of zsh >= 5.2
    Note for fish users: [2] please refer to this docs for more details https://fishshell.com/docs/current/#tab-completion

Usage:
  minikube completion SHELL [flags] [options]

Use "minikube options" for a list of global command-line options (applies to all commands).

zsv may also support shell command completion as part of its binary.

Here's a small PoC for Bash: https://github.com/iamazeem/zsv-bash-completion

Demo:

zsv-bash-completion-demo

liquidaty commented 6 months ago

Is this something that could easily be added as a makefile optional target that would install command completion when run?

iamazeem commented 6 months ago

Once we have consistent formatting for all the commands then this can simply be automated at runtime. The completion script can provide the suggestions at runtime using the help text. Currently, the help text differs from command to command as reported under #154.