#WindowsTerminal – Open Windows Terminal from the current edit file path in Visual Studio Code @code

Buy Me A Coffee

Hi !

I’m a big fan of Windows Terminal, and is my default external terminal in Visual Studio Code. However, today I learned a very cool tip:

Launch an external Windows Terminal from Visual Studio Code, and the terminal will open using the path of the current Workspace in VSCode.

Fabian explains the full scenario (see references), however the magic is to add the “startingDirectory = %__CD__%” in the profile definition in Windows Terminal Settings. In example, line 14:

      // Anaconda - Drone 02 Virtual Environment
      "guid": "{A87154C9-7846-479F-88CE-2C29BE4653CC}",
      "name": "Anaconda - Drone 02 VEnv",
      "commandline": "pwsh.exe -ExecutionPolicy ByPass -NoExit -Command & 'C:\\ProgramData\\Anaconda3\\shell\\condabin\\conda-hook.ps1' ; conda activate 'C:\\ProgramData\\Anaconda3' ; conda activate drone02; cls ",
      "hidden": false,
      "fontFace": "Cascadia Code",
      "fontSize": 12,                
      "backgroundImage": "D:/OneDrive/Pictures/WindowsTerminalBackgrounds/Ava_Wallpaper_Logo_Center_Thermal_Lat7270_5470.png",
      "backgroundImageOpacity" : 0.2,
      "colorScheme": "VibrantInk",
      "useAcrylic": true,
      "acrylicOpacity": 0.8,
      "startingDirectory": "%__CD__%" 

Awesome ! To open an external Terminal, press

Ctrl + Shift + C

and that’s it!

new terminal opened in the current workspace folder

Happy coding!


El Bruno


#Windows10- #WindowsTerminal and Anaconda, bonus: start an Anaconda Virtual Environment

Buy Me A Coffee

Hi !

Windows Terminal (WT) is one of the coolest tools I’ve using in the last couple of years. I’m not an expert, and not even a fan of CLIs, however I assume working with WT is super cool.

Bonus: If you speak Spanish, I shared my own thoughts about this with Juan and Eduard in a podcast episode here.

On top of this, I also use Anaconda a lot. And, now that we can launch and use Anaconda from a PowerShell Prompt, I think I should spend some time trying to figure out how to have Anaconda inside Windows Terminal.

windows terminal new profiles for Anaconda

I will assume that you know the basis of Windows Terminal profiles. As a WT user, we can create as many profiles as we want to have different tools available. This is my starting point to use Anaconda and Windows Terminal.

Note: Check References for Donovan Brown post about working with profiles.

Create a new profile to launch Anaconda in Windows Terminal

Let’s go to Windows Terminal Settings to create a new profile for Anaconda. In order to do this, I’ll copy and paste an existing profile, update the Guid and complete the following values.

  • guid: create and paste a new Guid
  • name: I defaulted this to Anaconda
  • commandline: this is the tricky one. So I’ll describe the steps below.

I browse to [C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Anaconda3 (64-bit)] and view the properties for the [Anaconda PowerShell Prompt]. Then copy the Target value and use the value in the commandline element.

get properties from shortcut for Anaconda Command Prompt

That should be enough to have a new profile to work with Anaconda. When we open a new tab for Anaconda, we can see that it open the standard virtual environment (base).

default anaconda prompt in windows terminal

1st step done, have Anaconda integrated with Windows Terminal !

Start an Anaconda Virtual Environment in a new Windows Terminal Tab

Moving on, I’ll create and activate a new Virtual Environment named [drone], with the following commands.

conda create -n drone pip python=3.7
conda activate drone

Now I have a new environment named [drone], and I want to have a shortcut in Windows Terminal to open a new tab with this VirtualEnv activated. I copy & paste the definition of the Anaconda profile, used a new Guid, and added, the following command to the end of the line:

conda activate drone
virutal env openend in windows terminal

As you can see in the previous image, when I open a new tab for my Drone Virtual Env, I already have it loaded. I also added a [cls] command at the end, so I can start with a clean environment.

Finally, and for reference, this is my current Windows Terminal settings file including the 2 Anaconda profiles.

Happy coding!


El Bruno