microsoft / microsoft/terminal

Opening Split Screen Terminal from a script is impossible

Open
#19,732 7 comments 0 reactions 0 assignees View on GitHub
Issue-Bug Needs-Attention Needs-Triage
Dominant language
C++
Stars
105k
Forks
9.6k
Avg merge
3d 17h
Merged PRs (30d)
29

Description

Copilot also couldn't figure this out and ran in circles.
How can one call WindowsTerminal to create multiple terminals with splits from a script? It only works from an interactive terminal, requiring you to copy paste the command.

### Windows Terminal version

1.23.13503.0

### Windows build number

10.0.22631.0

### Other Software

_No response_

### Steps to reproduce

I want to start 4 terminals when I run `npm run watch`. The following commands all work from an interactive shell, but do not work if you put them in a script or inside a package.json script.

**cmd.exe**:
`wt.exe -w 'LFE' -p 'bash' --title 'watch-dev' --suppressApplicationTitle npm run watch-dev ; split-pane -H -p 'Powershell' --title 'watch-prod' --suppressApplicationTitle npm run watch-prod ^; move-focus up ; split-pane -p 'Powershell' --title 'watch-tsc' --suppressApplicationTitle npm run watch-tsc ; move-focus down ; split-pane -p 'Powershell' --title 'watch-test' --suppressApplicationTitle npm run watch-test
`

**bash.exe**:
`wt.exe -w 'LFE' -p 'Powershell' --title 'watch-dev' --suppressApplicationTitle npm run watch-dev \; split-pane -H -p 'Powershell' --title 'watch-prod' --suppressApplicationTitle npm run watch-prod \; move-focus up \; split-pane -p 'Powershell' --title 'watch-tsc' --suppressApplicationTitle npm run watch-tsc \; move-focus down \; split-pane -p 'Powershell' --title 'watch-test' --suppressApplicationTitle npm run watch-test
`

**pwsh.exe**:
```wt.exe -w 'LFE' -p 'Powershell' --title 'watch-dev' --suppressApplicationTitle npm run watch-dev `; split-pane -H -p 'Powershell' --title 'watch-prod' --suppressApplicationTitle npm run watch-prod `; move-focus up `; split-pane -p 'Powershell' --title 'watch-tsc' --suppressApplicationTitle npm run watch-tsc `; move-focus down `; split-pane -p 'Powershell' --title 'watch-test' --suppressApplicationTitle npm run watch-test```

### Expected Behavior

To be able to launch a split screen terminal from a script.

### Actual Behavior

None of the following work:

1. **From package.json**
```jsonc
{
"scripts": {
"watch-dev": " webpack --config webpack/webpack.dev.js --watch",
"watch-prod": " webpack --config webpack/webpack.prod.js --watch",
"watch-tsc": " tsc -project tsconfig.json --watch",
"watch-test": " npx jest --maxWorkers=25% --watchAll",
"watch": "wt.exe -w 'LFE' -p 'Powershell' --title 'watch-dev' --suppressApplicationTitle npm run watch-dev \\; split-pane -H -p 'Powershell' --title 'watch-prod' --suppressApplicationTitle npm run watch-prod \\; move-focus up \\; split-pane -p 'Powershell' --title 'watch-tsc' --suppressApplicationTitle npm run watch-tsc \\; move-focus down \\; split-pane -p 'Powershell' --title 'watch-test' --suppressApplicationTitle npm run watch-test",
// Doesnt work if create scripts for this either
"watch:pwsh": "pwsh inSplitTerminal.ps1 -- watch-dev watch-prod watch-tsc watch-test",
"watch:bash": "bash inSplitTerminal.sh -- watch-dev watch-prod watch-tsc watch-test",
"watch:cmd": "cmd inSplitTerminal.cmd -- watch-dev watch-prod watch-tsc watch-test",
},
}
```

2. **From Powershell script: inSplitTerminal.ps1**
- Fails when run directly (the same command used successfully from an interactive console earlier). Just create an empty file & paste the command that interactively worked earlier.
- Fails with Invoke-Expression
- Fails with Start-Process
- Fails with `[ProcessStartInfo]::new('wt.exe')` & `Arguments`
- Fails with `[ProcessStartInfo]::new('wt.exe')` & `ArgumentList`
- Fails with `cmd /c "$cmd"`
3. **From bash script: inSplitTerminal.sh**
- Fails when run directly (the same command used successfully from an interactive console earlier)
- Fails with eval
4. **From cmd/bat script: inSplitTerminal.cmd**
- Fails when run directly (the same command used successfully from an interactive console earlier)
- I didn't bother generating a string to invoke from the passed in args.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the command from package.json and the referenced inSplitTerminal.ps1, inSplitTerminal.sh, and inSplitTerminal.cmd scripts under each shell. Compare interactive and scripted invocation, then verify that a script can launch the four requested panes and commands with the expected titles and profiles.

Written by the indexing model from the issue text.

Assessment

Tech stack
bash, powershell, shell
Domain
cli, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.