⛳

dbtのタブ補完(completion)

に公開

普段使ってるツールの使ってない機能を使ってみる Advent Calendar 2025です。

タブ補完(Completion)とは

シェルでタブを押した時に、その入力しているコマンドに応じた固有の補完をしてくれる機能です。例えばAWS CLI等、色々な補完が公開されています。

dbtのタブ補完(bash/zsh)

dbt labsがbash用のタブ補完のスクリプトを公開してくれています。
(zshの場合bashのタブ補完のインポート機能で利用できるらしい)

例として、下のモデル・テストがあるとします。

> dbt ls
23:17:45  Running with dbt=1.10.15
23:17:45  Registered adapter: duckdb=1.10.0
23:17:46  Found 3 models, 4 data tests, 468 macros
sandbox.example.fail_model
sandbox.example.my_first_dbt_model
sandbox.example.my_second_dbt_model
sandbox.example.not_null_my_first_dbt_model_id
sandbox.example.not_null_my_second_dbt_model_id
sandbox.example.unique_my_first_dbt_model_id
sandbox.example.unique_my_second_dbt_model_id

runのselector(sオプション)を入力してtabを押すと、モデルの候補が表示されます。

> dbt run -s
.gitignore           .python-version      .user.yml            .venv                fail_model           my_first_dbt_model   my_second_dbt_model  sandbox.*            sandbox.example.*

注意

ちなみにこの補完はmanifest.jsonを見ているので、manifest.jsonがないと補完されません。

> rm target/manifest.json
> dbt ls -s
# 補完されない

dbtのタブ補完(fish)

dbt-labs製ではないですが、fish版のdbtのタブ補完を公開してくれてる方がいます。

fisherでインストールすると

> fisher install theodotdot/dbt.fish
# (シェル再起動必要かも)

bash版のタブ補完と同様に利用することができます。
(表示はちょっと違いますね)

> dbt ls -s 
.*  fail_model  my_first_dbt_model  my_second_dbt_model  sandbox.*  sandbox.example.*

Discussion