Visual Studio Code - Open file with folder from terminal (code) - bash

i'm trying to make a bash script that basically creates a new directory and opens it directly through visual studio code
i've managed to do that, however, now i want to make it automatically add a 'README.md' file, and open it WITH the new folder
thank you
i couldn't find anything on the internet, nor with the code help command.

solved - run:
code /path/to/folder/ /path/to/file/
documentation for vsc cli

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.

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

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.

Visual studio: How to open visual studio in current folder from cmd line

Does anyone know how to open Visual studio from the command line from the current
working directory. I know that when using VS code this is very simple. You just type code . and it works. Here, I'm searching for the Visual studio equivalent.
Anyone an idea?
Found it:
devenv ./mysolutionname.sln
To get this to work, you need to make sure that devenv is contained in your PATH variable.
Also you need to run this cmd as an administrator. You can open a window from your file explorer in your current folder as an administrator, by typing ALT-F and then use arrow button||letters to navigate. Press Enter on cmd|powershell as administrator.
Tip: If you start from an empty folder, you can use dotnet-cli to create a empty sln file
dotnet new sln mysolutionname
Also you can create a new project and add it to the solution using the dotnet-cli
dotnet new console -n myprojectname
dotnet sln add myprojectname
According to the documentation there's no such switch. There is no way to set the curent working directory. But you can open an existing solution.

Is there a way to change the extensions folder location for Visual Studio Code?

I've put Visual Studio Code on OneDrive, for the purpose of syncing it with its settings across my devices.
However, extensions are stored in %USERPROFILE%\.vscode\extensions on Windows.
Is it possible to change this folder's location so I can put it in the main Visual Studio Code folder?
At first I thought that copying the extensions in the resources\app\extensions of Visual Studio Code folder will be a nice workaround, but that doesn't work.
I've also searched for a solution on the documentation page and in the user settings, with no results.
What I did - after installing Visual Studio Code for the first time, I checked the documentation and added at the end of 'Target' field of editor's shortcut the following (there's a space before the two dashes):
--extensions-dir="DRIVELETTER:\VSCODE\extensions"
--user-data-dir="DRIVELETTER:\VSCODE\settings"
where DRIVERLETTER and VSCODE are the corresponding drive and directory where Visual Studio Code is installed. So mine looks like this:
"D:\Microsoft VS Code\Code.exe" --extensions-dir="D:\Microsoft VS Code\extensions"
Here is for the user data directory:
"D:\Microsoft VS Code\Code.exe" --user-data-dir="D:\Microsoft VS Code\settings"
Accessing the 'Target' field is done by right-clicking the shortcut and choosing 'Properties'
Anyway, there's a simpler solution to that problem - just use the portable version of Visual Studio Code. It works under Windows, Linux, and macOS:
Enable Portable Mode
Windows and Linux
After unzipping the Visual Studio Code download, simply create a data folder within Visual Studio Code's folder:
|- VSCode-win32-x64-1.25.0-insider
| |- Code.exe (or code executable)
| |- data
| |- ...
From then on, that folder will be used to contain all Visual Studio Code data, including session state, preferences, extensions, etc.
The data folder can be moved to other Visual Studio Code installations. This is useful for updating your portable Visual Studio Code version: simply move the data folder to a newer extracted version of Visual Studio Code.
macOS
On macOS, you need to place the data folder as a sibling of the application itself. Since the folder will be alongside the application, you need to name it specifically so that Code can find it. The default folder name is code-portable-data:
|- Visual Studio Code.app
|- code-portable-data
Portable mode won't work if your application is in quarantine, which happens by default if you just downloaded Visual Studio Code. Make sure you remove the quarantine attribute, if portable mode doesn't seem to work:
xattr -dr com.apple.quarantine Visual\ Studio\ Code.app
Note: On Insiders, the folder should be named code-insiders-portable-data.
UPDATE 14.12.2021
From Visual Studio Docs
Note: Do not attempt to configure portable mode on an installation from the Windows User or System installers. Portable mode is only supported on the Windows ZIP (.zip) archive. Note as well that the Windows ZIP archive does not support auto update.
A little hack:
Create a symbolic link to the folder %USERPROFILE%\.vscode\extensions under the Visual Studio Code install path.
https://code.visualstudio.com/docs/editor/extension-gallery
code --extensions-dir 'new_directory_to_set'
Set the root path for extensions.
Follow the below steps for changing the extension path in VS.
Set "code" path in environment variable.
path = VS_CODE_INSTALL_DIRECTORY/bin;
Open VS , in VS terminal execute the below command.
code --extensions-dir "new_directory_path"
Install the required extension.
All Done.
Note:Dont forget to vote the answer
According to this page, after installing VS Code we should make a language profilers folder like this:
mkdir code_profiles
cd code_profiles
mkdir code-ruby
cd code-ruby
mkdir exts
mkdir data
For Windows, I prepared a batch file (.bat) for each language I work on, it contains this line:
Start "" "D:\programs\VSCode\code.exe" --extensions-dir D:\programs\VSCode\code_profiles\code-python\exts --user-data-dir D:\programs\VSCode\code_profiles\code-python\data .
This is for Python. If I work on PHP, I will make code-php folder, then make exts and data folders in it and prepare another batch file for PHP, just like the one I made for python.
I put this batch file on the main project folder then double click on it to run VS Code with the preferred profile.

configure openCV Qt new functions

I'm struggling with the step from the official documentation
Extract it into a nice and short named directory like D:/OpenCV/dep/qt/ . Then you need to build it. Start up a Visual Studio Command Prompt (2010) by using the start menu search (or navigate through the start menu All Programs ‣ Microsoft Visual Studio 2010 ‣ Visual Studio Tools ‣ Visual Studio Command Prompt (2010)).
The Visual Studio command prompt
Now navigate to the extracted folder and enter inside it by using this console window. You should have a folder containing files like Install, Make and so on. Use the dir command to list files inside your current directory. Once arrived at this directory enter the following command:
configure.exe -release -no-webkit -no-phonon -no-phonon-backend -no-script -no-scripttools
-no-qt3support -no-multimedia -no-ltcg
...
My issue is that in this document Qt 4.7.3 was used, now, I dont know about that version because I wasn't able to find it but in the newer one there is not Install, Make files...
which ones should I use instead?
does anyone has any step for more recent version of Qt and VS that I can follow to get this done
I turns out I wasn't using the source file, which you can find here found the folder which contains the configuration and INTALLS files on the new version in a folder called qtbase continued with the steps from there on the OPENCV guide and everything worked alright on MSVS2012

Resources