Skip to content

Instantly share code, notes, and snippets.

@gabesumner
Last active August 31, 2018 01:48
Show Gist options
  • Save gabesumner/f482f3662ece55fd39f9d49873a5ee60 to your computer and use it in GitHub Desktop.
Save gabesumner/f482f3662ece55fd39f9d49873a5ee60 to your computer and use it in GitHub Desktop.
A small bash script that provides shortcuts for several common Salesforce DX commands.
#!/bin/bash
case $1 in
list)
# sfdx list
/usr/local/bin/sfdx force:org:list
;;
push)
if [ "$2" == "over" ]
then
# sfdx push over
/usr/local/bin/sfdx force:source:push --forceoverwrite
else
# sfdx push
/usr/local/bin/sfdx force:source:push
fi
;;
pull)
if [ "$2" == "over" ]
then
# sfdx pull over
/usr/local/bin/sfdx force:source:pull --forceoverwrite
else
# sfdx pull
/usr/local/bin/sfdx force:source:pull
fi
;;
status)
/usr/local/bin/sfdx force:source:status -a
;;
open)
if [ -z "$2" ]
then
# sfdx open - Just open the default scratch org
/usr/local/bin/sfdx force:org:open
else
# sfdx open [alias]
/usr/local/bin/sfdx force:org:open -u $2
fi
;;
login)
# sfdx login [alias]
/usr/local/bin/sfdx force:auth:web:login -a $2
;;
delete)
# sfdx delete [org]
/usr/local/bin/sfdx force:org:delete -u $2
;;
permset)
# sfdx permset [permset]
/usr/local/bin/sfdx force:user:permset:assign -n $2
;;
create)
/usr/local/bin/sfdx force:project:create --projectname $2
;;
scratchme)
# sfdx scratchme
/usr/local/bin/sfdx force:org:create -s -f config/project-scratch-def.json -a $2
;;
display)
# sfdx display [org]
# Gets the password
/usr/local/bin/sfdx force:org:display -u $2
;;
setpassword)
# sfdx setpassword [alias]
/usr/local/bin/sfdx force:user:password:generate -u $2
;;
retrieve)
#sfdx retrieve [package] [alias]
# Retrieves a package from a production site and converts it to an SFDX project.
sfdx force:mdapi:retrieve -s -p $2 -u $3 -r ./mdapiout
unzip ./mdapiout/unpackaged.zip -d mdapiout
sfdx force:mdapi:convert -r ./mdapiout -d ./force-app
rm -rf mdapiout
find . -name \*.dup -print | awk '{gsub(/^|$/,"\"");print;gsub(/\.dup\"$/,"\"")}1' | xargs -n2 mv
;;
defaulthub)
/usr/local/bin/sfdx force:config:set defaultdevhubusername=$2
;;
default)
/usr/local/bin/sfdx force:config:set defaultusername=$2
;;
deploy)
# sfdx deploy [alias]
# Deploys an SFDX project to a production org.
/usr/local/bin/sfdx force:source:convert -d ./mdapiout
rm -rf mdapiout/profiles
#perl -i -pe 'BEGIN{undef $/;} s/\s+<types>\s+<name>Profile<\/name>.*?<\/types>//s' ./mdapiout/package.xml
/usr/local/bin/sfdx force:mdapi:deploy -d ./mdapiout -w 5 -u $2
rm -rf mdapiout
;;
*)
/usr/local/bin/sfdx $@
;;
esac
@gabesumner
Copy link
Author

Assuming you're using a Mac, and that your shell is Bash. Put this in your ~/bin folder, do a "chmod 755 sfdx", then update your .bashrc file to contain $HOME/bin at the start of your $PATH. Now you can type "sfdx list", "sfdx open", "sfdx push", etc. Easier to type, easier to remember.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment