2

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!

  • did you get it to work? – jmh Jun 29 at 23:18
  • I did, thanks for asking. – Ronan Jun 30 at 22:02
3

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.

| improve this answer | |
  • Better answer than mine. But mine should work. Takes a little longer. I have about 30 aliases in my .bash_profile file yet I didn't even think of doing it that way! lol – jmh Jun 27 at 3:03
  • 1
    Note that starting in macOS Catalina, the default interactive shell is zsh, so you'd put that in ~/.zprofile instead of ~/.bash_profile. – Gordon Davisson Jun 27 at 3:04
  • 2
    Or you could just follow VS Code's published instructions, at code.visualstudio.com/docs/setup/… . But no one reads instructions. – Marc Wilson Jun 29 at 21:23
0

You could write a series of 1 line scripts and make them executable. In your example, a script named vscode would contain the one line you describe above. then you could

chmod +x vscode

and then just type vscode and return to run it.

| improve this answer | |
  • You need to first add a shebang and then your script code, so not really one-liners. – user3439894 Jun 27 at 3:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .