Search code examples
zsh

Cannot pass param behind equals to zsh alias


I am trying to setup an alias where I can pass a parameter behind equals sign, i.e.

sfdx force:config:set defaultusername=foo

I have tried few ways, for example this

alias dxd='sfdx force:config:set defaultusername={$1}'
alias dxd='sfdx force:config:set defaultusername='
alias dxd='sfdx force:config:set defaultusername=$1'

But it always get an error:

ERROR:  Setting variables must be in the format <key>=<value> or <key>="<value with spaces>" but found master.

I am assume there is a space added after equals, resulting something like this:

sfdx force:config:set defaultusername= foo

I guess there's something special about how zsh threats params?

The intended syntax is dxd foo.


Solution

  • Aliases won't accept arguments; only functions do. For your case this should work:

    dxd() { sfdx force:config:set defaultusername=$1 }
    

    Then invoke it as you've specified:

    dxd foo