running vs code from the command line on mac

Today was my FIRST in person FRC (FIRST Robotics Challenge) meeting since COVID showed up. Very exciting! Right now the older students are teaching the younger students. Today was an excellent intro the the UNIX/Git Bash command line. Towards the end, they showed that you can type “code” at the Git Bash prompt and have VS Code open automatically. Then a student asked how to do it on Mac.

There’s an easy way to do it and a hard way to do it. I went with the hard way because I thought I knew what to do. If we had gone the easy way, we would have been done in the meeting. Which proves the point of the importance of reading documentation.

The easy way

Courtesy of the setup docs for Mac

  1. Open VS Code (using Spotlight Search/the UI)
  2. Open the command palette (command + shift + p)
  3. Type path
  4. Choose option Shell Command: Install ‘code’ command in PATH command.
  5. Close VS Code
  6. Open a new terminal window
  7. Type code

The hard way

I divided the hard way into five steps to explain what to do. We got through step 1 and the beginning of step 2 during the meeting.

The Hard Way – Step 1: Find VS Code

I expected VS Code to be in /Applications. On my computer, it is at /Applications/Visual Studio That was not where the student had it. After some googling and failed attempts at using Stack Overflow threads, we found an excellent tip.

  1. Hold option and click the Apple in the top nav
  2. Choose “System Information”
  3. Software > Applications
  4. Wait patiently. No really. Wait some more
  5. Scroll all the way down to “V” and click “Visual Studio Code”
  6. Read the location. It was under <user home>/wpiilib/vscode or something like that. (WPILive is the robotics library)

The student had the good idea to open it in Finder and drag to /Applications. (Open finder and hold option while choosing “Go”) for extra options.

The Hard Way – Step 2: Figure out where “code” executable is and add to PATH

We poked around in the Visual Studio folder but ran out of meeting time. At home, I tried again; this time using the find command

% pwd
/Applications/Visual Studio
% find . -name code -print

Ok. Then. It’s under Contents/Resources/app./bin/code in side the app directory. I knew it was somewhere in there.

The Hard Way – Step 3: Add to PATH

If you are still on the old shell, add the following line to your <user home>/.bash_profile file. If you’ve switched to zsh, use the .zshrc file instead.

export PATH="$PATH:/Applications/Visual Studio"

The Hard Way – Step 4: Reload the file

Run one of these to run the file you just edited and have your change take effect

source .bash_profile
source .zshrc

The Hard Way – Step 5: Launch VS Code



VS Code from Microsoft JDConf

The FIRST FRC robotics team I mentor uses VS Code. So I’m always comparing it to Eclipse. This meant that Loiane’s talk today on using it was useful. It was good to see how a professional developer is using VSCode. And how to set it up properly. It was also nice seeing it for stuff I use outside the FIRST robotics ecosystem (Spring, Tomcat, etc)

My notes from Loiane Groner’s talk – @Loiane

Install Visual Studio Code for Java – comes with JDK and extensions wan

tIf already have (or get from FIRST robotics and are using that package), Loiane uses these extensions:

  • Java + Spring Extensions Back (by Microsoft)
  • Spring Boot extension back
  • Tomcat (or Jetty)
  • SonarLint
  • XML
  • Lombok
  • Checkstyle
  • Docker

Other notes

  • Can edit the JSON settings to point to multiple Java runtime for different versions.
  • One is default.Java overview page – show each time, not just went new. This will show each time open a Java project and get major shortcuts/docs
  • Demo of command pallet
  • Views on left side – ex Java projects (shows all classes), Tomcat
  • Remember to right click for menus
  • Can open pom.xml, right click and add dependencies
  • May be slow on load because analyzing project