dbt-labs/dbt-completion.bash

New completion script for zsh

Closed this issue · 2 comments

b-per commented

Hi!

I just came across the bash completion script, and while I am using zsh myself, the current script worked to auto-complete the models, with 2 caveats:

  1. I had to update it to make it work with folders including spaces
  2. Prefixing with '+' and '@' didn't work and was throwing errors

So, after spending a bit of time understanding zsh completion mechanism I have created the following script:
Gist link

--

Installation

  • If you are using Oh My Zsh, just save the _dbt file in ~/.oh-my-zsh/completions (create the folder if it doesn't exist)
  • The script has been tested on macOS and with zsh version 5.8

Pros:

  • Completion for models works with strings in the middle of the model names (e.g. typing invoice will match models customer_invoice and vendor_invoice
  • Completion has been set up for some flags and commands (listing most of the flags available when running dbt run, dbt test and dbt docs as well as the global flags)
  • Support for '+' and '@' has been replicated from the bash completion script

Cons:

  • Currently, when running dbt run or dbt test the models will be suggested even though there is no model selection flag defined or if the model selection flag is not the last one in the list

--

Happy to submit a PR and share the script on this repo if people want to use it and improve it.

Hey @camfrout, a PR for this would be most welcome!

Resolved by #7