Open KalleOlaviNiemitalo opened 1 year ago
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
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
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.
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:
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:
Position()
as a member of NewTabArgs
--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?
Yes.
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:
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: 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.
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.
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"
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
):
Any help would be much appreciated
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[@]}"
}
Hi is this issue still open?
Hi is this issue still open?
Yep.
Description of the new feature/enhancement
I have a Bash function that opens a tab with PowerShell in the current directory:
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 towt 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.