Skip to content

Instantly share code, notes, and snippets.

@Pitt-Pauly
Last active October 26, 2018 06:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pitt-Pauly/c5a3e116d686b590177236268ff5c15d to your computer and use it in GitHub Desktop.
Save Pitt-Pauly/c5a3e116d686b590177236268ff5c15d to your computer and use it in GitHub Desktop.
VSCode & NVM Unity launcher + script

Launch VSCode with the default Node version set - via Unity

So VSCode has an annoying bug that forces people to run nvm set before launching VSCode for it to recognise which node binary to use.

Since I am lazy I made a unity .desktop shortcut for it which launches a small script that does exactly that!

This could be extended in the future to include the option to use other Node versions too, and launching VSCode with them with the right click options.

I hope this saves people some time :)

Happy coding!

Setup:

  1. copy the code.desktop file to $HOME/.local/share/applications/ where the other unity .desktop files live.

  2. Make it exectuable using sudo chmod +x $HOME/.local/share/applications/code.desktop.

  3. Put the launch_nvm_n_code script into your $HOME/bin or /usr/local/bin (or somewhere on your PATH),

  4. and make it executable to with chmod like before.

  5. Go back to your code.desktop file. Just double click on the code.desktop file to see if it works. If it does then right click the icon and 'lock to launcher'. Or just drag the file onto the launcher.

Enjoy! Should this not work, leave a comment below!

[Desktop Entry]
Name=Visual Studio Code + node set
Comment=Code Editing. Redefined.
GenericName=Text Editor
Exec=launch_nvm_n_code
Terminal=true
Icon=code
Type=Application
StartupNotify=true
StartupWMClass=Code
Categories=Utility;TextEditor;Development;IDE;
MimeType=text/plain;inode/directory;
Actions=new-empty-window;without-node;
Keywords=vscode;
X-Desktop-File-Install-Version=0.22
[Desktop Action new-empty-window]
Name=New Empty Window
Terminal=false
Exec=/usr/share/code/code --new-window %F
Icon=code
[Desktop Action without-node]
Name=Run VSCode normally
Terminal=false
Exec=/usr/share/code/code --unity-launch %F
#!/bin/bash
. $HOME/.nvm/nvm.sh && nvm use default && /usr/share/code/code --unity-launch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment