tabby icon indicating copy to clipboard operation
tabby copied to clipboard

Windows CWD detection

Open Eugeny opened this issue 6 years ago • 5 comments

CWD detection on Windows is far from perfect - I currently rely on either parsing the CWD from the prompt (which is not 100% reliable), or the shell being configured to report CWD via an escape sequence.

This leads to new tabs sometimes not reusing the current tab's CWD and CWD not being restored on terminal restart.

Eugeny avatar Oct 28 '19 11:10 Eugeny

How do you do this in fish?

Dunky13 avatar Mar 06 '20 13:03 Dunky13

The latest nightly now includes experimental implementation that reads CWD from the shell process' memory. Currently only works with cmd/clink.

Eugeny avatar Feb 07 '21 11:02 Eugeny

Maybe this can help? https://learn.microsoft.com/en-us/windows/terminal/tutorials/new-tab-same-directory

In this tutorial, you learn how to configure your shell to allow Windows Terminal to open tabs in the same path.

I was able to get Powershell works but not for MINGW/Git Bash (in Windows Terminal and Tabby).

The Shell working directory reporting opens in ~/AppData/Local/Programs/Tabby

mariovalney avatar Mar 23 '23 18:03 mariovalney

@mariovalney thanks! But CWD detection already works for both CMD and Powershell. I need to come up with a similar snippet for Cygwin and MSYS2...

Current state:

Done a bit of more exact testing (for later reference):

Shell Accepts WD Reports CWD
PowerShell
Git-bash
cmd.exe (stock)
cmd.exe (clink)
MSYS2
WSL
Cygwin

Eugeny avatar Mar 23 '23 19:03 Eugeny

The Shell working directory reporting opens in ~/AppData/Local/Programs/Tabby

Hey @Eugeny & @mariovalney! I was hitting the same issue, and found an alternative that's working for me. Instead of $(pwd) as described in Shell working directory reporting, I'm using:

${PWD/#\/c/C:}

This issue appeared to be occurring for me because in Git Bash pwd would yield a path like /c/Users/something. Presumably a path of this form is being passed to the shell process of the new tab which isn't a valid Windows path and therefore results in the fallback to ~/AppData/Local/Programs/Tabby.

The above snippet just replaces the starting /c with C:, so this simple snippet wouldn't work for other drives!

With that change I was able to open new Git Bash, Powershell & CMD tabs in the correct working directory detected from a source Git Bash tab - hope this helps!

carl-hartshorn avatar Mar 19 '24 17:03 carl-hartshorn