How to replace commands in the terminal

terminal

I want to be able to type a short command and have that be replaced with a longer one. For example, typing vscode could run something like open -a "Visual Studio Code". I know this is possible in Linux, but is there any way to do this in MacOS?

Thanks in advance!

Best Answer

You should be able to do the same as your were doing in Linux in macOS.

As an example, if using bash, adding

alias vscode="open -a 'Visual Studio Code'"

to your .bash_profile file will let you just type vscode in Terminal to open Visual Studio Code.


Note: If you are running macOS Catalina, or later, and have not installed a more recent version of bash and are using the default zsh shell, then put aliases in your ~/.zprofile, or the appropriate file for the shell you are running.

Also, you might want to read Visual Studio Code on macOS to add the code executable to your PATH or path, depending on your shell.