bat-extras icon indicating copy to clipboard operation
bat-extras copied to clipboard

ZSH autocompletion support

Open Haltarys opened this issue 2 years ago • 3 comments

Would it be possible to add ZSH autocompletion to the commands? It would be very useful, especially to autocomplete man pages.

Haltarys avatar Jan 04 '23 09:01 Haltarys

I would love to, but I don't really have experience with zsh or creating autocompletion definitions for it. I might take a shot at trying to create some in the future when time permits, but in the meantime, if anybody else knows how to and is willing to create them, I would be happy to accept them in a PR :)

eth-p avatar Mar 21 '23 07:03 eth-p

Hello, I found a workaround to complete man pages for the batman command. This applies the _man completion function to the batman command (which ZSH or Oh My ZSH already apply by default to the man command):

# alias `man` to `batman` (this is optional)
command -v batman >/dev/null && alias man='batman'

# batman command completion (must be after sourcing Oh My Zsh: `source $ZSH/oh-my-zsh.sh`)
command -v batman >/dev/null && compdef _man batman

The command -v batman >/dev/null && bit ensures that the batman command exists before applying the patches. It doesn't solve the issue for all the bat-extras utilities, but this was the most annoying one for me.

Haltarys avatar Mar 21 '23 14:03 Haltarys

On my MacOS machine, I managed to get it working with

autoload -U +X compinit && compinit
compdef batman=man

While I'd like to do proper completions for the other commands at some point, compdef batman=man will suffice for now. I'll add that as a vendor completion later this weekend.

eth-p avatar Mar 24 '23 18:03 eth-p