11

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.

DJ Poland
  • 667
  • 6
  • 21

6 Answers6

6

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.

LeaveTheCapital
  • 2,130
  • 1
  • 4
  • 11
  • 2
    update - 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
3

I've found something interesting.... This worked for me... You can put:

"startingDirectory": "./"

In the terminal configuration....

Example

{
    // Make changes here to the powershell.exe profile.
    "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
    "name": "Windows PowerShell",
    "commandline": "powershell.exe",
    "startingDirectory": "./",
    "hidden": false
},
joshhunt
  • 4,685
  • 2
  • 31
  • 56
gdonega
  • 55
  • 1
  • 1
  • 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
  • 3
    Unfortunately 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
  • Tried with Ubuntu in a tab, did not work – Mike Slinn Apr 02 '21 at 04:39
2
  1. Open the windows terminal
  2. Click the dropdown button
  3. Click the settings option
  4. set the startingDirectory value to "./"
Example
"profiles":
    {
        "defaults":
        {
            // Put settings here that you want to apply to all profiles.
            "startingDirectory": "./" <---- set this value
        }

George C.
  • 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
  • The answer is updated, I hope is better now @AmitVerma – George C. Mar 03 '21 at 16:19
1

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.

apena
  • 1,486
  • 7
  • 18
1
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

Celso Jr
  • 114
  • 9
0

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: WT Debian profile

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.

SGM1
  • 918
  • 1
  • 10
  • 22