I want to simply start a new tab in the same folder as my previous tab that I was in. Is this possible, and if so how? This is with the windows terminal by the way.
6 Answers
This is not currently possible, as explained here https://github.com/microsoft/terminal/issues/1437 the issue is closed at the moment but could perhaps be re-opened in future.
![](../../users/profiles/10110621.webp)
- 2,130
- 1
- 4
- 11
-
2update - this is now being tracked under this issue, the spec hasn't been agreed upon at time of writing https://github.com/microsoft/terminal/issues/3158 – LeaveTheCapital Jun 02 '20 at 07:35
I've found something interesting.... This worked for me... You can put:
"startingDirectory": "./"
In the terminal configuration....
{
// Make changes here to the powershell.exe profile.
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"name": "Windows PowerShell",
"commandline": "powershell.exe",
"startingDirectory": "./",
"hidden": false
},
-
Welcome to Stackoverflow. Answers should not be screenshots, please post code in a codeblock. Also this answer shows how to to open a tab the current directory not the cuurent directory of previous tab as the user asks. – apena Aug 13 '20 at 15:37
-
3Unfortunately this only lets you determine the starting directory, it doesn't copy the previous directory when opening a new tab. – joshhunt Dec 28 '20 at 07:58
-
- Open the windows terminal
- Click the dropdown button
- Click the settings option
- set the
startingDirectory
value to"./"
"profiles":
{
"defaults":
{
// Put settings here that you want to apply to all profiles.
"startingDirectory": "./" <---- set this value
}
![](../../users/profiles/6600549.webp)
- 4,745
- 10
- 39
- 70
-
While this piece of code may provide a solution to the question, it's better to add context as to why/how it works. This can help future users refer to and eventually apply this knowledge to their own code. You are also likely to have positive feedback/upvotes from users, when the code is explained. – Amit Verma Mar 03 '21 at 07:27
-
You can always rewrite setting json evertime you open a tab but its a shell specific hack.
Put this function into $PROFILE
(make sure to adjust $path
)
function sd {
$path = 'C:\Users\Admin\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json'
((Get-Content -path $path) -replace '"startingDirectory":.*', ("`"startingDirectory`": `"$pwd`"") -replace "\\", "\\") | Set-Content -Path $path
}
Solution taken from here.
![](../../users/profiles/5705559.webp)
- 1,486
- 7
- 18
dotnet tool install -g p2u
p2u dir ${PWD}
Then CTRL+SHIFT+D
Hopefully it will work with split pane as well
Same idea of @apena but now with a dotnet tool. For further details: https://github.com/celsojr/p2u
![](../../users/profiles/1812371.webp)
- 114
- 9
-
A simple CTLS+SHIFT+D did the trick for me - what I was looking for. Thx – Hunsoul May 07 '21 at 19:03
Also a similar vein as @apena's post as it is specific to bash.
In my case I wanted Debian to open on my current working directory.
Although I couldn't exactly get this behavior I was able to get it to open the last directory visited (effectively) using a few hacks:
In my linux distro, I added this to my .bashrc
to intercept all calls to cd
and store the last call to cd
into a destination of my choice.
cd() {
builtin cd "$@" ; echo $PWD > /opt/chdir/lastestdir
}
Next, since Windows Terminal didn't let me inline the command, I created this batch script to in a custom location:
@echo off
for /F "tokens=*" %%n IN (\\wsl$\Debian\opt\chdir\lastestdir) DO @(wsl.exe -d Debian --cd \\wsl$\Debian%%n)
NOTE: \\wsl$\Debian
is the path to my distro within Powershell, and the \opt\chdir\lastestdir
is based on the path I used in the previous step.
Next, I edited the profile for Debian in Windows terminal to point at my script:
I'm open for suggestions, but this let me happily duplicate my current directory to the next tab as long as it was the last terminal I had changed directory in.
![](../../users/profiles/2133905.webp)
- 918
- 1
- 10
- 22