Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

output shell completion script by bat --completion <shell> command #2057

Open
tigerinus opened this issue Feb 2, 2022 · 5 comments · May be fixed by #3126
Open

output shell completion script by bat --completion <shell> command #2057

tigerinus opened this issue Feb 2, 2022 · 5 comments · May be fixed by #3126
Labels

Comments

@tigerinus
Copy link

Currently the autocompletion script comes only with the source.

A better approach, would be something like bat --completion=bash.

Here is my current bash_completion script executed at login:

source <($HOME/.local/bin/helm completion bash)
source <($HOME/.local/bin/kustomize completion bash)
source <($HOME/.local/bin/pip completion --bash)
source <($HOME/.local/bin/stern --completion=bash)
source <($HOME/.local/node/bin/npm completion)
source $HOME/.local/bat/autocomplete/bat.bash # this can become `bat --completion=bash` 
@tigerinus tigerinus added the feature-request New feature or request label Feb 2, 2022
@abuGit
Copy link

abuGit commented Mar 15, 2022

The bash completion should be placed in this ~/.local/share/bash-completion/completions directory.

From github:bash-completion

Q. Where should I install my own local completions?

A. Put them in the completions subdir of $BASH_COMPLETION_USER_DIR (defaults to $XDG_DATA_HOME/bash-completion or ~/.local/share/bash-completion if $XDG_DATA_HOME is not set) to have them loaded automatically on demand when the respective command is being completed. See also the next question's answer for considerations for these files' names, they apply here as well. Alternatively, you can write them directly in ~/.bash_completion which is loaded eagerly by our main script.

For system wide installation (e.g. packaging deb, ...) the completion may be placed in /etc/bash_completion.d/ .

@tigerinus
Copy link
Author

@abuGit - I don't think you understand my feature request.

I am asking for a completion script built-in from bat completion command directly.

Yes, bat completion command does not exist - that's what I am asking for.

@petemounce
Copy link

I would really like this, too, for zsh. It's really convenient to be able to do {tool} completion --shell {zsh|bash|fish} at install-time to also install/refresh shell completions.

@tolik518
Copy link

I haven't figured out a good way to get the completions when installing bat using cargo. This issue would solve the problem imo.

@plwalsh
Copy link

plwalsh commented Nov 13, 2024

I haven't figured out a good way to get the completions when installing bat using cargo. This issue would solve the problem imo.

This worked for me:

TARGET_DIR=tmp
CMP_SCRIPT=bat.bash

mkdir -p $TARGET_DIR
cargo install --locked --target-dir $TARGET_DIR bat
mkdir -p ~/.local/share/bash-completion/completions
cp $(find $TARGET_DIR -name $CMP_SCRIPT) ~/.local/share/bash-completion/completions/

Edit: Actually this method looks cleaner/easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants