microsoft / terminal

The new Windows Terminal and the original Windows console host, all in the same place!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

wt new-tab open near current tab

KalleOlaviNiemitalo opened this issue · comments

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 #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.

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 .

newTabPosition #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

This function is somewhat like duplicating a tab #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.

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

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

HEY ! CAN I HAVE MY HANDS ON THIS ISSUE ?

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

hello
is this issue still open?

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.

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:

void TerminalPage::_CreateNewTabFromPane(std::shared_ptr<Pane> pane, uint32_t insertPosition)

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.

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.

commented

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

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"

commented

I'm currently working on this feature request here: 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