Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wt new-tab open near current tab #14687

Open
KalleOlaviNiemitalo opened this issue Jan 16, 2023 · 18 comments
Open

wt new-tab open near current tab #14687

KalleOlaviNiemitalo opened this issue Jan 16, 2023 · 18 comments
Labels
Area-Commandline wt.exe's commandline arguments good first issue This is a fix that might be easier for someone to do as a first contribution Help Wanted We encourage anyone to jump in on these. Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal.
Milestone

Comments

@KalleOlaviNiemitalo
Copy link

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

@KalleOlaviNiemitalo KalleOlaviNiemitalo added the Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. label Jan 16, 2023
@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Jan 16, 2023
@237dmitry
Copy link

237dmitry commented 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 .

@KalleOlaviNiemitalo
Copy link
Author

KalleOlaviNiemitalo commented Jan 16, 2023

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

@KalleOlaviNiemitalo
Copy link
Author

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.

@237dmitry
Copy link

237dmitry commented 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

@zadjii-msft
Copy link
Member

Okay there's two thoughts here:

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 zadjii-msft added Product-Terminal The new Windows Terminal. Issue-Task It's a feature request, but it doesn't really need a major design. Area-Commandline wt.exe's commandline arguments and removed Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. labels Jan 16, 2023
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Jan 16, 2023
@zadjii-msft zadjii-msft added the Help Wanted We encourage anyone to jump in on these. label Jan 16, 2023
@zadjii-msft zadjii-msft added this to the Backlog milestone Jan 16, 2023
@carlos-zamora carlos-zamora added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting good first issue This is a fix that might be easier for someone to do as a first contribution and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Jan 18, 2023
@fxxxxr
Copy link

fxxxxr commented Aug 22, 2023

HEY ! CAN I HAVE MY HANDS ON THIS ISSUE ?

@zadjii-msft
Copy link
Member

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

@daemon-reconfig
Copy link

hello
is this issue still open?

@lhecker
Copy link
Member

lhecker commented Oct 5, 2023

Yes.

@AlexJMercer
Copy link

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.

@lhecker
Copy link
Member

lhecker commented 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:

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.

@KalleOlaviNiemitalo
Copy link
Author

KalleOlaviNiemitalo commented 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.

@nivowski
Copy link

nivowski commented 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

@zadjii-msft
Copy link
Member

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"

@nivowski
Copy link

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

@ezParth
Copy link

ezParth commented 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[@]}"

}

@Ismith507

This comment was marked as off-topic.

@zadjii-msft

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Commandline wt.exe's commandline arguments good first issue This is a fix that might be easier for someone to do as a first contribution Help Wanted We encourage anyone to jump in on these. Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal.
Projects
Status: Should be written
Development

No branches or pull requests