- Salesforce Development Posts by Matt Lacey

SFDX and Bash... A Few Handy Aliases

Posted 2019-01-09

I know some people like to use zsh and some funky auto-complete tools etc. to makes their lives with sfdx a bit easier, but I'm often stuck in the past and like to keep things simple. I use sfdx on a few different machines, generally always in bash, and so find a few alises in my .bashrc file help out a lot. If you don't know what that file is, it's basically a bash script that lives in your home directory and is run automagically by bash when you start a session. alias allows you to specify an alias for a specific command, so I use it to fight the rather excessive verbosity of the dx cli.

The ones I use most often (and configure on each machine) are:

alias dxpush='sfdx force:source:push'
alias dxopen='sfdx force:org:open'
alias dxpull='sfdx force:source:pull'
alias dxlist='sfdx force:org:list'

It's pretty obvious what these do, but they save on typing for the most common situations.

Easier Switching

Switching scratch orgs can be a bit cumbersome, but to make it easier there's two things you can do:

  1. Always specify an alias (using -a) when creating a new scratch org, this means you don't need to type or work out the crazy user names that dx generates by default
  2. Add the following bash function to your .bashrc file:
dxswitch() {
  sfdx force:config:set defaultusername="$1"

With this in place, you can simply type dxswitch [orgalias], which is much easier to remember!

If you do have a fancy setup involving bash or other shells, please do share in the comments!