thiagowfx's avatar

Β¬ just serendipity πŸ€ (not just serendipity)

zsh: setopt magic_equal_subst

β€’ 90 words β€’ 1 min β€’ updated

⚠️ This post is over one year old. It may no longer be up to date or relevant. Opinions may have changed.

Problem statement: Write the following command line in zsh:

shell
% terraform plan -var-file=../../../config/global-dns-changer-

Now press <TAB>.

Expected: Filename expansion.

Observed:

No matches for: `filename' or `file'

Ugh. How about some magic πŸͺ„?

shell
setopt magic_equal_subst

Now:

shell
% terraform plan -var-file=../../../config/global-dns-changer-<TAB>
completing file
global-dns-changer-{foo}.tfvars  global-dns-changer-{bar}.tfvars

Yay!

There’s a workaround if you don’t want to set the aforementioned option. Just remove the = character:

shell
% terraform plan -var-file ../../../config/global-dns-changer-<TAB>
completing file
global-dns-changer-{foo}.tfvars  global-dns-changer-{bar}.tfvars

I find it’s more convenient to have this option work in both situations though.

(via Reddit)