How to open file in a specific application from the command line - bash

I want to open a .md file in a repo in visual studio code from my command line. Does anyone know the command for this?
I am using the bash shell.

First, you need to have Visual Studio Code CLI. ( Try code --version in terminal to check if it's already installed or not ). You have to install it manually on mac OSX (see below). In windows and linux, the command line interface code should be readily available in the PATH.
To install it (in MAC)
Launch VS Code.
Open the Command Palette (⇧⌘P) and type ‘shell
command’ to find the Shell Command: Install ‘code’ command in PATH
command.
After that you can use:
code filename
to open the filename in Visual Studio.
For more information, click
code --help will give you more information.
For example, code -r filename will open the file in already opened Visual Studio window.

Related

alternative to 'code' visual studio in pycharm

Some of my coworkers use visual studio code. Personally I am already used to pycharm. I've seen my colleagues using code filename in the VSC terminal, so that it opens the file filename in a new VSC tab. Is there a similar alternative in pycharm?
Yes you can create a CLI launcher in the Tools menu "Create Command-line launcher"
The last part of the path is the name you decide to give the launcher e.g "pcharm" or "pyc" (anything of your choice) and save it.
Reload the terminal, and run the command with your file name.

File compare on macOS with FreeFileSync and Visual Studio Code

I struggling to make it work for me.
I have FreeFileSync (v10.20) and Visual Studio Code (v1.43.0) installed on macOS Mojave (v10.14.6) and would like to add a file compare context menu command, so
Step 1:
I added Visual Studio Code to my path as explained on their site (https://code.visualstudio.com/docs/setup/mac#_launching-from-the-command-line):
Launch VS Code
Open the Command Palette (F1) and type 'shell command' to find the Shell Command: Install 'code' command in PATH command.
After this, I am able to launch Terminal and run:
code --diff
Step 2:
I added the following option to FreeFileSync Preferences at 'Customize context menu':
Description: Compare with Visual Studio Code
Command line: code --diff "%local_path%" "%local_path2%"
The issue:
So far, it does nothing. No errors. No windows opened. Why?
Thanks for your help in advance!
Craby
OK, just I found out the solution myself, I hope this will help you guys, too:
The solution is to configure Visual Studio Code as external file compare (diff) tool in FreeFileSync as follows:
Description: Compare with Visual Studio Code
Command line: /Applications/Visual\ Studio\ Code.app/Contents/MacOS/Electron --diff "%local_path%" "%local_path2%"
Note the \ backslashes to escape the spaces... without these it fails silently.
Enjoy!
Craby

How to install Visual Studio Code's `code` command permanently?

I just followed the top-voted answer here and successfully installed Visual Studio Code's code command in my terminal.
However, the code command fails to launch Visual Studio Code every time after I restart my MacBook Pro.
~ code
zsh: command not found: code
Is it possible to install code permanently so that I don't have to install it every time I turn on my MacBook Pro?
~ where code
/usr/local/bin/code
~ ls -l /usr/local/bin/code
lrwxr-xr-x 1 myName admin 167 Aug 5 13:41 /usr/local/bin/code -> /private/var/folders/bh/525lnbns1213cx2651s97my00000gp/T/AppTranslocation/EA379FC4-05D2-4739-BE49-1D8870E47B8A/d/Visual Studio Code.app/Contents/Resources/app/bin/code
I also find out that the folder EA379FC4-05D2-4739-BE49-1D8870E47B8A get deleted after I restart my laptop.
This is the reason that I cannot run code after the laptop is restarted.
Why is code installed in a temporary folder?
My MacBook Pro's version is macOS Sierra version 10.12.6
The reason that code get installed in a temporary folder is that I placed Visual Studio Code.app in Downloads folder.
After I moved it to Applications folder, launched it, and installed code command, the code is not installed in a temporary folder anymore.
you can this code in visual studio code command palette to register shell command.
Open the command palette.
shell command
and run this command to install 'code' command
install 'code' command in PATH
And then restart terminal

'makecert' is not recognized as an internal or external command in command prompt

For creating certificate run this command:
makecert -r -pe -n "CN=effectLabs Server" -b 01/01/2011 -e 01/01/2020 -sky exchange C:\myCerts\ELServer.cer -sv C:\myCerts\ELServer.pvk
Following error occurred in command prompt:
'makecert' is not recognized as an internal or external command,
operable program or batch file.
On Windows 10, this tool has been renamed to the Developer Command Prompt for VS2015. You can find this by simply pressing the Windows key, and then searching for 'Developer Command Prompt'.
You need to use the Visual Studio command prompt to use the makecert utility on the command line.
On windows 10, I came across with the same issue. In spite of running my Developer Command Prompt for VS2017 as administrator, I got the same error. But when I installed Windows SDK then makecert command successfully got run.
You have to use Visual Studio command prompt.
You can find it in:
In Windows 8
On the Start screen, press the Windows logo key Windows logo + Z. (To open the Start screen, press the Windows logo key Windows logo on your keyboard.)
Choose the Apps view icon at the bottom of the screen and then press V. The list will include all installed Visual Studio command prompts.
Choose the Developer Command Prompt (or the command prompt you want to use).
In Windows 7
Choose Start, expand All Programs, and then expand Microsoft Visual Studio.
Depending on the version of Visual Studio you have installed, choose Visual Studio Tools, Visual Studio Command Prompt, or the command prompt you want to use.
for anyone still still getting this error even after installing the mentioned above SDK, make sure to include the path to the makecert file in the system env path, which should be along the lines of : C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin

How to embed command shell in Visual Studio

I would like to be able to embed a command line interpreter inside a dockable window in Visual Studio. Is there any nice way to do this?
See the VS Command shell project
Checkout Open Command Line by Mads Kristensen. note it doesn't really "embed" the shell in VS, rather it adds a keyboard shortcut to open the shell at the project directory
it supports bash, powershell, git bash, ...etc
In Visual Studio click Tools -> NuGet Package Manager -> Package Manager Console
It embeds a cmd prompt with everything on your %PATH% you'd expect.

Resources