MicrosoftDocs / terminal

Creative Commons Attribution 4.0 International
468 stars 170 forks source link

ZSH new tab same directory #730

Closed Affan-7 closed 2 months ago

Affan-7 commented 7 months ago

[Enter feedback here]

It's not working with ZSH.

https://learn.microsoft.com/en-us/windows/terminal/tutorials/new-tab-same-directory#zsh


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

zadjii-msft commented 7 months ago

Can you give us some additional info? How all do you have zsh and the Terminal configured? Which versions (of each)?

Affan-7 commented 7 months ago

ZSH version : zsh 5.8.1 (x86_64-ubuntu-linux-gnu) Windows terminal version: 1.18.3181.0

The command prompt is working exactly as intended, I have used the following commands to configure the command prompt as shown in the documentation.

set PROMPT=$e]9;9;$P$e\%PROMPT%
setx PROMPT "%PROMPT%"

However the duplicate tab functionality doesn't preserve the current directory in WSL ZSH.

I configured the ZSH by adding the following lines in the .zshrc file.

keep_current_path() {
  printf "\e]9;9;%s\e\\" "$(wslpath -w "$PWD")"
}
precmd_functions+=(keep_current_path)

Here is a video, showing the behavior of the terminal.

https://github.com/MicrosoftDocs/terminal/assets/72978371/e58a6e61-f781-43c0-b34b-b28c323580b8

Affan-7 commented 7 months ago

@zadjii-msft

I have also found that there is another profile named ubuntu which is disabled for the dropdown menu. If we enable it, open a new tab using that profile and duplicate the tab, it preserves the directory!

https://github.com/MicrosoftDocs/terminal/assets/72978371/dac01dac-57ec-4519-8328-3419f242c547

nguyen-dows commented 2 months ago

Thanks! That profile is not compatible with starting directories. You can find more info here