I’m trying to define bash auto-completion for teamocil so that when I type teamocil <tab> it should complete with the file names in the folder ~/.teamocil/ without the file extensions. There’s an example for zsh in the website:
compctl -g '~/.teamocil/*(:t:r)' teamocil
how can I use this in bash?
Edit: Influenced by michael_n ‘s answer I have come up with a one-liner:
complete -W "$(teamocil --list)" teamocil
Here’s a generalized version of another completion script I have that does something similar. It assumes a generic hypothetical command “flist”, using some directory of files defined by FLIST_DIR to complete the command (omitting options).
Modify the following for your program (
teamocil), change the default dir from$HOME/flistto$HOME/.teamocil), define your own filters/transformations, etc; and then just source it (e.g.,. ~/bin/completion/bash_completion_flist), optionally adding it to your existing list of bash completions.Notes:
complete -o ...) is a bit of a hack to work across different versions of bash.base=${filename%.*}), but the easiest is arguably the simple sed with some assumptions about the filename format.