From 6bd4ed2e0853d8d23dacf24dff9cba2254d1d3b0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 18 Dec 2025 20:10:23 +0000 Subject: [PATCH 1/4] Initial plan From d44de5f67eae808baa6e1bd4bfa1c913c39f9d7d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 18 Dec 2025 20:13:43 +0000 Subject: [PATCH 2/4] Add comprehensive examples for executing commands in new tabs Co-authored-by: mattwojo <7566797+mattwojo@users.noreply.github.com> --- TerminalDocs/command-line-arguments.md | 101 +++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/TerminalDocs/command-line-arguments.md b/TerminalDocs/command-line-arguments.md index 67372893..449e92dd 100644 --- a/TerminalDocs/command-line-arguments.md +++ b/TerminalDocs/command-line-arguments.md @@ -156,6 +156,107 @@ Here's an example of calling Windows Terminal to open a new tab with a PowerShel wt new-tab PowerShell -c Start-Service ; new-tab cmd /k dir ``` +### Executing commands in new tabs + +When you open a new tab, you can execute commands in that tab by passing a `commandline` argument. The `commandline` must be an executable (with optional arguments), not shell functions or aliases. + + +#### [Command Prompt](#tab/windows) + +To open a new tab and run a command: + +```cmd +wt new-tab cmd /k echo Hello World +``` + +To open multiple tabs with different commands: + +```cmd +wt new-tab cmd /k dir ; new-tab cmd /k "echo Tab 2" ; new-tab PowerShell -NoExit -Command "Get-Date" +``` + +#### [PowerShell](#tab/powershell) + +To open a new tab and run a PowerShell command: + +```powershell +wt new-tab PowerShell -NoExit -Command "Get-ChildItem" +``` + +To open multiple tabs with different commands: + +```powershell +wt new-tab PowerShell -NoExit -Command "Get-Date" `; new-tab PowerShell -NoExit -Command "Get-Location" +``` + +#### [Linux](#tab/linux) + +To open a new tab and run a command in bash: + +```bash +cmd.exe /c "wt.exe" new-tab bash -c "ls -la" +``` + +To open a new tab and keep it open after running a command, use `bash -c` with an interactive shell: + +```bash +cmd.exe /c "wt.exe" new-tab bash -c "cd /home && exec bash" +``` + +To open multiple tabs with different commands and titles: + +```bash +cmd.exe /c "wt.exe" new-tab --title "Tab1" bash -c "cd /home && exec bash" \; new-tab --title "Tab2" bash -c "ls && exec bash" +``` + +**Important notes for WSL/Linux:** + +- **Bash functions and aliases are not available**: When you run `wt.exe new-tab`, it starts a new shell session. Functions and aliases defined in your `.bashrc` are only available in interactive shells. +- **To use bash functions**: You need to source your `.bashrc` file or define the function inline: + + ```bash + cmd.exe /c "wt.exe" new-tab bash -c "source ~/.bashrc && my_function && exec bash" + ``` + +- **To run a script file**: Create a script file and execute it directly: + + ```bash + # Create a script file first + echo '#!/bin/bash' > /tmp/myscript.sh + echo 'echo "Running script"' >> /tmp/myscript.sh + echo 'npm start' >> /tmp/myscript.sh + chmod +x /tmp/myscript.sh + + # Then run it in a new tab + cmd.exe /c "wt.exe" new-tab bash -c "/tmp/myscript.sh && exec bash" + ``` + +- **Use `exec bash` to keep the tab open**: Without `exec bash`, the tab will close when the command completes. + +**Example: Opening multiple tabs with commands from a bash function** + +```bash +function launch_my_project() { + # Tab 1: Just open a bash shell + cmd.exe /c "wt.exe" -w 0 new-tab --title "Main" --tabColor '#4d658d' bash -c "exec bash" + + # Tab 2: Run a command and keep the shell open + cmd.exe /c "wt.exe" -w 0 new-tab --title "Client" --tabColor '#468b76' -p "Ubuntu-22.04" bash -c "cd ~/my-project/client && npm install && exec bash" + + # Tab 3: Source .bashrc and run a function + cmd.exe /c "wt.exe" -w 0 new-tab --title "Daemon" --tabColor '#7484a6' -p "Ubuntu-22.04" bash -c "source ~/.bashrc && my_daemon_start_function && exec bash" + + # Tab 4: Run a direct command + cmd.exe /c "wt.exe" -w 0 new-tab --title "Server" --tabColor '#aa5f37' -p "Ubuntu-22.04" bash -c "cd ~/my-project/server && npm start" + + # Focus on the first tab + cmd.exe /c "wt.exe" focus-tab -t 1 +} +``` + +--- + + ### Target a specific window The following examples show how to use the `--window,-w` option to target specific windows. From 261f2b4b1f0191fa4b96705db0c2026df0fc9e51 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 18 Dec 2025 20:15:13 +0000 Subject: [PATCH 3/4] Fix tab index comment and add WSL context clarification Co-authored-by: mattwojo <7566797+mattwojo@users.noreply.github.com> --- TerminalDocs/command-line-arguments.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/TerminalDocs/command-line-arguments.md b/TerminalDocs/command-line-arguments.md index 449e92dd..0e1cacea 100644 --- a/TerminalDocs/command-line-arguments.md +++ b/TerminalDocs/command-line-arguments.md @@ -191,6 +191,8 @@ wt new-tab PowerShell -NoExit -Command "Get-Date" `; new-tab PowerShell -NoExit #### [Linux](#tab/linux) +These examples are for WSL (Windows Subsystem for Linux) environments. Windows Terminal runs on Windows, so you need to call `wt.exe` through `cmd.exe` from WSL. + To open a new tab and run a command in bash: ```bash @@ -249,7 +251,7 @@ function launch_my_project() { # Tab 4: Run a direct command cmd.exe /c "wt.exe" -w 0 new-tab --title "Server" --tabColor '#aa5f37' -p "Ubuntu-22.04" bash -c "cd ~/my-project/server && npm start" - # Focus on the first tab + # Focus on the second tab (index 1) cmd.exe /c "wt.exe" focus-tab -t 1 } ``` From 22efa5a8220d99c99dabc9e67174a9350e342799 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 18 Dec 2025 20:16:24 +0000 Subject: [PATCH 4/4] Improve tab focus comment clarity Co-authored-by: mattwojo <7566797+mattwojo@users.noreply.github.com> --- TerminalDocs/command-line-arguments.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TerminalDocs/command-line-arguments.md b/TerminalDocs/command-line-arguments.md index 0e1cacea..e85ba0b6 100644 --- a/TerminalDocs/command-line-arguments.md +++ b/TerminalDocs/command-line-arguments.md @@ -251,7 +251,7 @@ function launch_my_project() { # Tab 4: Run a direct command cmd.exe /c "wt.exe" -w 0 new-tab --title "Server" --tabColor '#aa5f37' -p "Ubuntu-22.04" bash -c "cd ~/my-project/server && npm start" - # Focus on the second tab (index 1) + # Focus on the Client tab (index 1) cmd.exe /c "wt.exe" focus-tab -t 1 } ```