Add alias permanently to MacOS

Writing out lengthy commands (like database) every time you use them can be a pain.

Here, the alias command, which shortens lengthy commands to just a single word, comes in handy.

For instance, in Salesforce, to open a specific organisation in the browser, we use the following command:

1
sfdx force:org:open -u {OrgAlias}

We can shorten this command into one word, like “browse,” as below.

1
alias browse="sfdx force:org:open -u"

If you add the above command to your terminal and then the type the below command, it’s effectively the same as the long command.

1
browse {OrgAlias}

To make these changes permanent, we need to add them to the /.zshrc file.

1
vi ~/.zshrc

Switch to insert mode (:i) in vi and add the same alias command, to the file

1
alias browse="sfdx force:org:open -u"

Use (:wq) to save the file and quit.

To activate these changes, either open the terminal or, in the same window, use the source command as follows:

1
source ~/.zshrc

Now in this window or any new tab you can use the alias.

updatedupdated2024-01-172024-01-17