8

I was recently interested by new Windows Terminal, so after testing it a bit, I wanted to have one profile which will instantly start development environment of my gatsby website. So I created another profile with config as follows:

"guid": "given unique guid",
"name": "Gatsby DEV",
"startingDirectory": "C:\\Projects\\gatsby-website\\",
"commandline": "gatsby develop"

Unfortunately, after choosing the profile from a menu, I can only see a tab blink, meaning it opens and closes immediately. When I added "closeOnExit": false option, it didn't close, but the shown tab is empty.

Has anyone tried it already and succeeded?

mtk
  • 81

3 Answers3

7

I use the following to start a Node.JS environment -

{    
  "guid": "{CBEAD37E-E945-4569-AAFA-091A9D3321C9}",
  "name": "Node.js",
  "commandline": "cmd /k \"F:\\Program Files\\nodejs\\nodevars.bat\"",
  "colorScheme": "Vintage",
  "hidden": false
},

The profile above spawns a CMD shell using the /k flag. /k instructs the shell to execute the command and then return to the cmd prompt allowing further input. In the case of the script above it spawns a shell; runs the batch file that initializes the environment variables and then returns you to a fully configured prompt.

If your tab is appearing and then disappearing immediately it is because the command you are running is providing a return code to announce that it has completed. By wrapping this in a command shell (with the /k flag) the return code is delivered to cmd and consumed rather than being passed to Windows Terminal which will instruct the tab to close.

elaverick
  • 226
4

Here is a modified version of elaverick to run commands on Windows Terminal when starting up Powershell:

{
    // Make changes here to the powershell.exe profile.
    "guid": "<Your guid goes here>",
    "name": "Custom Powershell",
    "commandline": "powershell.exe -NoExit \"<Your command goes here>\"",
    "hidden": false
},

Note the -NoExit flag and the escaped quotes for JSON. Replace <Your command goes here>

Real
  • 141
2

Just in case anyone else is new to windows terminal besides me. Real's answer worked for me, but that config belongs in your settings.json file, which by default is

"C:\Users\USERNAME\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json"

Within that file you have something like:

{
    "$schema": "https://aka.ms/terminal-profiles-schema",
    ...
    "profiles": 
    {
        "defaults": {},
        "list": 
        [
            {
                "commandline": "cmd /k \"F:\\Program Files\\nodejs\\nodevars.bat\""
                "guid": "{some autogenerated guid here}",
                "hidden": false,
                "name": "custom cmd",
                "startingDirectory": "C:\\my_starting_dir"
            ...
            },
        ...
        ]
    ...
    }
...    
}
Aaron P
  • 21
  • 2