wt new-tab open near current tab #19215

Open
opened 2026-01-31 06:37:07 +00:00 by claunia · 21 comments
Owner

Originally created by @KalleOlaviNiemitalo on GitHub (Jan 16, 2023).

Description of the new feature/enhancement

I have a Bash function that opens a tab with PowerShell in the current directory:

vspwsh ()
{
    wt new-tab --profile "Developer PowerShell for VS 2017" --startingDirectory .
}

I'd like this to place the new PowerShell tab next to the Bash tab in which I run the command. That way, it would be easier for me to keep track of the purpose of each tab, keeping tabs near each other when they are for working on the same directory.

This is somewhat related to https://github.com/microsoft/terminal/issues/3158 but would not depend on any escape sequences emitted by the shell.

Proposed technical implementation details (optional)

Add a --near-current-tab option to wt new-tab. When specified, use the WT_SESSION environment variable to find the session, tab, and window in which the command was run, and place the new tab near that one.

If both --near-current-tab and --window are specified, then ignore WT_SESSION and instead use the selected tab of the specified window.

Originally created by @KalleOlaviNiemitalo on GitHub (Jan 16, 2023). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> # Description of the new feature/enhancement I have a Bash function that opens a tab with PowerShell in the current directory: ```sh vspwsh () { wt new-tab --profile "Developer PowerShell for VS 2017" --startingDirectory . } ``` I'd like this to place the new PowerShell tab next to the Bash tab in which I run the command. That way, it would be easier for me to keep track of the purpose of each tab, keeping tabs near each other when they are for working on the same directory. This is somewhat related to <https://github.com/microsoft/terminal/issues/3158> but would not depend on any escape sequences emitted by the shell. # Proposed technical implementation details (optional) Add a `--near-current-tab` option to `wt new-tab`. When specified, use the WT_SESSION environment variable to find the session, tab, and window in which the command was run, and place the new tab near that one. If both `--near-current-tab` and `--window` are specified, then ignore WT_SESSION and instead use the selected tab of the specified window.
Author
Owner

@237dmitry commented on GitHub (Jan 16, 2023):

There is the parameter in Preview version:

"newTabPosition": "afterCurrentTab" //  or "afterLastTab" (default)

Command will open new tab near current tab:

wt -w 0 nt -p "<profile>" -d .
@237dmitry commented on GitHub (Jan 16, 2023): There is the parameter in Preview version: ``` "newTabPosition": "afterCurrentTab" // or "afterLastTab" (default) ``` Command will open new tab near current tab: ``` wt -w 0 nt -p "<profile>" -d . ```
Author
Owner

@KalleOlaviNiemitalo commented on GitHub (Jan 16, 2023):

newTabPosition https://github.com/microsoft/terminal/issues/12955 is a global option; I want afterCurrentTab just for this function and not for opening tabs via Windows Terminal key combinations.

It would be okay to reuse the enum type though. wt new-tab --position afterCurrentTab

@KalleOlaviNiemitalo commented on GitHub (Jan 16, 2023): `newTabPosition` <https://github.com/microsoft/terminal/issues/12955> is a global option; I want `afterCurrentTab` just for this function and not for opening tabs via Windows Terminal key combinations. It would be okay to reuse the enum type though. `wt new-tab --position afterCurrentTab`
Author
Owner

@KalleOlaviNiemitalo commented on GitHub (Jan 16, 2023):

This function is somewhat like duplicating a tab https://github.com/microsoft/terminal/issues/14313 but I'm specifying a different profile for the duplicate. OTOH, if I had manually changed the color of the Bash tab, it would be okay for the new PowerShell tab to inherit that.

@KalleOlaviNiemitalo commented on GitHub (Jan 16, 2023): This function is somewhat like duplicating a tab <https://github.com/microsoft/terminal/issues/14313> but I'm specifying a different profile for the duplicate. OTOH, if I had manually changed the color of the Bash tab, it would be okay for the new PowerShell tab to inherit that.
Author
Owner

@237dmitry commented on GitHub (Jan 16, 2023):

newTabPosition is a global option

Changing the configuration via settings.json for most settings happens on the fly.
I am not against --near switch. This more convenient.
As a workaround I would add the necessary actions to function.

Something like:


# pwsh
# $WT_SETTINGS is the custom environment variable

function vsbash {
param (
    [Parameter()]
    [switch] $near
)

    $json = Get-Content $WT_SETTINGS | ConvertFrom-Json
    
    if ($near) { $json.newTabPosition = 'afterCurrentTab' }
    else { $json.newTabPosition = 'afterLastTab' }

    $json | ConvertTo-Json -Depth 5 | Set-Content $WT_SETTINGS

    wt --window 0 new-tab --profile "bash" --startdirectory "."
}
$ vsbash -near
@237dmitry commented on GitHub (Jan 16, 2023): > `newTabPosition` is a global option Changing the configuration via settings.json for most settings happens on the fly. I am not against `--near` switch. This more convenient. As a workaround I would add the necessary actions to function. Something like: ```powershell # pwsh # $WT_SETTINGS is the custom environment variable function vsbash { param ( [Parameter()] [switch] $near ) $json = Get-Content $WT_SETTINGS | ConvertFrom-Json if ($near) { $json.newTabPosition = 'afterCurrentTab' } else { $json.newTabPosition = 'afterLastTab' } $json | ConvertTo-Json -Depth 5 | Set-Content $WT_SETTINGS wt --window 0 new-tab --profile "bash" --startdirectory "." } ``` ``` $ vsbash -near ```
Author
Owner

@zadjii-msft commented on GitHub (Jan 16, 2023):

Okay there's two thoughts here:

  • "I want to duplicate the current tab, but with a different profile" - #10232 (with a touch of #11913)
  • "I want a commandline arg for afterCurrentTab" - Yea, we can use this thread to track that request.

We might want to workshop the parameters a bit. --position feels like it should be shortened to -p, which is already used by --profile. But maybe it doesn't need to be shortened at all! wt new-tab --newTabPosition ... does seem a little redundant.

Vague todo list:

  • Add Position() as a member of NewTabArgs
  • Add --position parsing to AppCommandlineArgs
@zadjii-msft commented on GitHub (Jan 16, 2023): Okay there's two thoughts here: * "I want to duplicate the current tab, but with a different profile" - #10232 (with a touch of #11913) * "I want a commandline arg for `afterCurrentTab`" - Yea, we can use this thread to track that request. We might want to workshop the parameters a bit. `--position` feels like it should be shortened to `-p`, which is already used by `--profile`. But maybe it doesn't need to be shortened at all! `wt new-tab --newTabPosition ...` does seem a little redundant. Vague todo list: * [ ] Add `Position()` as a member of `NewTabArgs` * [ ] Add `--position` parsing to `AppCommandlineArgs`
Author
Owner

@gautam376 commented on GitHub (Aug 22, 2023):

HEY ! CAN I HAVE MY HANDS ON THIS ISSUE ?

@gautam376 commented on GitHub (Aug 22, 2023): HEY ! CAN I HAVE MY HANDS ON THIS ISSUE ?
Author
Owner

@zadjii-msft commented on GitHub (Aug 22, 2023):

GO FOR IT! FEEL FREE TO COMMENT IF YOU HAVE ANY QUESTIONS ☺️

@zadjii-msft commented on GitHub (Aug 22, 2023): GO FOR IT! FEEL FREE TO COMMENT IF YOU HAVE ANY QUESTIONS ☺️
Author
Owner

@daemon-reconfig commented on GitHub (Oct 5, 2023):

hello
is this issue still open?

@daemon-reconfig commented on GitHub (Oct 5, 2023): hello is this issue still open?
Author
Owner

@lhecker commented on GitHub (Oct 5, 2023):

Yes.

@lhecker commented on GitHub (Oct 5, 2023): Yes.
Author
Owner

@AlexJMercer commented on GitHub (Dec 13, 2023):

Hello,

I'd like to take this up as my very first contribution to get into open source.
I've not done this before, and I'd really appreciate if you could help me out with getting started.

After cloning the repo and opening the OpenConsole.sln (assuming that's what I'm supposed to open) in VS2017:

  1. How do I understand what files I should be looking out for?
  2. How to test my changes? (I assume I need to build the application but I don't understand how to do that even after going through the CONTRIBUTING.MD)

Any pointers or links to external references would be really helpful. Thank you for your time.

@AlexJMercer commented on GitHub (Dec 13, 2023): #### Hello, I'd like to take this up as my very first contribution to get into open source. I've not done this before, and I'd really appreciate if you could help me out with getting started. After cloning the repo and opening the `OpenConsole.sln` (assuming that's what I'm supposed to open) in VS2017: 1. How do I understand what files I should be looking out for? 2. How to test my changes? (I assume I need to build the application but I don't understand how to do that even after going through the `CONTRIBUTING.MD`) Any pointers or links to external references would be really helpful. Thank you for your time.
Author
Owner

@lhecker commented on GitHub (Jan 8, 2024):

As a prerequisite you need to use VS 2022: https://github.com/microsoft/terminal#prerequisites
If I remember correctly, the relevant function for new-tab insertion is this one: b02316b37c/src/cascadia/TerminalApp/TabManagement.cpp (L228)
It already has an index parameter which defaults to -1 (= unspecified), so only the callers need to be updated to use the current tab-index instead.
To test your changes simply build WindowsTerminal and run it. We'll then test the changes again around the time we merge your PR.

@lhecker commented on GitHub (Jan 8, 2024): As a prerequisite you need to use VS 2022: https://github.com/microsoft/terminal#prerequisites If I remember correctly, the relevant function for new-tab insertion is this one: https://github.com/microsoft/terminal/blob/b02316b37c78fd2efefdfba676a504e816176fdf/src/cascadia/TerminalApp/TabManagement.cpp#L228 It already has an index parameter which defaults to -1 (= unspecified), so only the callers need to be updated to use the current tab-index instead. To test your changes simply build WindowsTerminal and run it. We'll then test the changes again around the time we merge your PR.
Author
Owner

@KalleOlaviNiemitalo commented on GitHub (Jan 8, 2024):

Please note the request is for opening a new tab near the "tab in which I run the command", which might not be the selected tab of the window. For example, say I have a window with three tabs A, B, and C, and I run sleep 10 && wt new-tab --position afterCurrentTab in tab A. The command should then create the new tab D near tab A, and the resulting order of tabs should be A D B C, even if I select tab C during the 10-second delay.

@KalleOlaviNiemitalo commented on GitHub (Jan 8, 2024): Please note the request is for opening a new tab near the "tab in which I run the command", which might not be the selected tab of the window. For example, say I have a window with three tabs A, B, and C, and I run `sleep 10 && wt new-tab --position afterCurrentTab` in tab A. The command should then create the new tab D near tab A, and the resulting order of tabs should be A D B C, even if I select tab C during the 10-second delay.
Author
Owner

@nivowski commented on GitHub (Feb 7, 2024):

I have seen that you can open a tab with a shortcut keybind but how do you achieve to open a new tab using wt command? Whenever I use wt new-tab, it always open a new Terminal instance.So, is there actually a different command or option to achieve this behaviour? Thank you in advance

@nivowski commented on GitHub (Feb 7, 2024): I have seen that you can open a tab with a shortcut keybind but how do you achieve to open a new tab using `wt` command? Whenever I use `wt new-tab`, it always open a new Terminal instance.So, is there actually a different command or option to achieve this behaviour? Thank you in advance
Author
Owner

@zadjii-msft commented on GitHub (Feb 8, 2024):

So, wt new-tab will obey your "New instance behavior" setting. So by default (as of 1.20), this will open a new window. But you can override that with something like wt -w 0 new-tab, where -w 0 says "run this wt command in the current window"

@zadjii-msft commented on GitHub (Feb 8, 2024): So, `wt new-tab` will obey your ["New instance behavior" setting](https://learn.microsoft.com/en-us/windows/terminal/customize-settings/startup#new-instance-behavior). So by default (as of 1.20), this will open a new window. But you can override that with something like `wt -w 0 new-tab`, where `-w 0` says "run this `wt` command in the current window"
Author
Owner

@nivowski commented on GitHub (Feb 10, 2024):

I'm currently working on this feature request here: https://github.com/microsoft/terminal/compare/main...nivowski:terminal:feature/wt-new_tab_position

It run with success but doesn't work when trying to pass the --tabPosition parameter(wt -w 0 new-tab --tabPosition 4):

image

Any help would be much appreciated

@nivowski commented on GitHub (Feb 10, 2024): I'm currently working on this feature request here: https://github.com/microsoft/terminal/compare/main...nivowski:terminal:feature/wt-new_tab_position It run with success but doesn't work when trying to pass the --tabPosition parameter(`wt -w 0 new-tab --tabPosition 4`): ![image](https://github.com/microsoft/terminal/assets/41701732/fcd06c73-0dcc-4a29-bf75-9988d1fd83c6) Any help would be much appreciated
Author
Owner

@ezParth commented on GitHub (Apr 7, 2024):

vspwsh ()
{
local near_current_tab=0
local window_id=""

while [[ "$#" -gt 0 ]]; do
    case $1 in
        --near-current-tab)
            near_current_tab=1
            shift
            ;;
        --window)
            window_id="$2"
            shift 2
            ;;
        *)
            echo "Unknown option: $1"
            return 1
            ;;
    esac
done

if [[ $near_current_tab -eq 1 && -n $window_id ]]; then
    echo "Error: Both --near-current-tab and --window cannot be specified together."
    return 1
fi

local wt_args=("--profile" "Developer PowerShell for VS 2017" "--startingDirectory" ".")

if [[ $near_current_tab -eq 1 ]]; then
    if [[ -n $WT_SESSION ]]; then
        local session_id=$(echo "$WT_SESSION" | cut -d";" -f1)
        local tab_id=$(echo "$WT_SESSION" | cut -d";" -f2)
        local window_id=$(echo "$WT_SESSION" | cut -d";" -f3)
        wt_args+=("--window" "$window_id" "--tab" "$tab_id")
    else
        echo "Error: WT_SESSION environment variable not set."
        return 1
    fi
elif [[ -n $window_id ]]; then
    wt_args+=("--window" "$window_id")
fi

wt new-tab "${wt_args[@]}"

}

@ezParth commented on GitHub (Apr 7, 2024): vspwsh () { local near_current_tab=0 local window_id="" while [[ "$#" -gt 0 ]]; do case $1 in --near-current-tab) near_current_tab=1 shift ;; --window) window_id="$2" shift 2 ;; *) echo "Unknown option: $1" return 1 ;; esac done if [[ $near_current_tab -eq 1 && -n $window_id ]]; then echo "Error: Both --near-current-tab and --window cannot be specified together." return 1 fi local wt_args=("--profile" "Developer PowerShell for VS 2017" "--startingDirectory" ".") if [[ $near_current_tab -eq 1 ]]; then if [[ -n $WT_SESSION ]]; then local session_id=$(echo "$WT_SESSION" | cut -d";" -f1) local tab_id=$(echo "$WT_SESSION" | cut -d";" -f2) local window_id=$(echo "$WT_SESSION" | cut -d";" -f3) wt_args+=("--window" "$window_id" "--tab" "$tab_id") else echo "Error: WT_SESSION environment variable not set." return 1 fi elif [[ -n $window_id ]]; then wt_args+=("--window" "$window_id") fi wt new-tab "${wt_args[@]}" }
Author
Owner

@Ismith507 commented on GitHub (Apr 10, 2024):

Hi is this issue still open?

@Ismith507 commented on GitHub (Apr 10, 2024): Hi is this issue still open?
Author
Owner

@zadjii-msft commented on GitHub (Apr 15, 2024):

Hi is this issue still open?

Yep.
a screenshot of this issue still being open, based on the fact that it's labeled as open

@zadjii-msft commented on GitHub (Apr 15, 2024): > Hi is this issue still open? Yep. ![a screenshot of this issue still being open, based on the fact that it's labeled as open](https://github.com/microsoft/terminal/assets/18356694/ae243161-5065-4bbf-b8d4-7b7d560f6874)
Author
Owner

@NinjaZMY commented on GitHub (May 7, 2025):

any updates ? the problem is still persisting

@NinjaZMY commented on GitHub (May 7, 2025): any updates ? the problem is still persisting
Author
Owner

@Prasad-JB commented on GitHub (Aug 9, 2025):

Implementing support for question:* in the tagName parameter to return all matching results would be very useful for bulk data queries. This could be achieved by detecting the * wildcard in the backend (e.g., in plots2/app/api/srch/search.rb) and bypassing pagination or increasing the limit to include the full dataset. For large result sets, we could stream results or implement a server-side batch fetch to avoid performance bottlenecks. This enhancement would greatly improve API usability for data analysis workflows.

@Prasad-JB commented on GitHub (Aug 9, 2025): Implementing support for question:* in the tagName parameter to return all matching results would be very useful for bulk data queries. This could be achieved by detecting the * wildcard in the backend (e.g., in plots2/app/api/srch/search.rb) and bypassing pagination or increasing the limit to include the full dataset. For large result sets, we could stream results or implement a server-side batch fetch to avoid performance bottlenecks. This enhancement would greatly improve API usability for data analysis workflows.
Author
Owner

@shivam-dhir commented on GitHub (Jan 22, 2026):

Hi, I would love to work on this issue

@shivam-dhir commented on GitHub (Jan 22, 2026): Hi, I would love to work on this issue
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#19215