[Feature Request] Duplicate directory does not work properly in Windows Terminal. Suggest Clink lua addition to fix.
ABillBlakely opened this issue · comments
Version Information
Cmder version:Full version 1.3.25.386
Operating system: Windows 11
Windows Terminal: 1.24.250825002-preview
Cmder Edition
Cmder Full (with Git)
Description of the issue
I have mostly successfully configured cmder to work within windows terminal. I set this up manually following the guide with a user install of windows terminal. I am not using the packaged windows term cmder version in the dev repo. The one thing that was annoying me was that I could not get it to duplicate the tab (using ctrl+shift+d) and keep the working directory like it does in non-cmder shells like cmd.
MS has this documentation informing that you must emit an OSC9;9 escape sequence with the directory. Following their instruction for cmd did not work though.
Today I realized that it is because clink is controlling the prompt so I toyed around with clink a little and eventually got it to work.
save a .lua script to the user config file with these contents:
local emit_directory_to_osc9 = clink.promptfilter(10)
function emit_directory_to_osc9:filter(prompt)
return "\x1b]9;9;"..os.getcwd().."\x1b\\"..prompt
end
After saving use ctrl+x, ctrl+r to reload clink or close and open the terminal.
This adds the escape sequence before the prompt with the working directory and enables windows terminal to duplicate and split the terminals while preserving the directory. This is all invisible so it does not modify the appearance of the terminal.
I would suggest something similar be added to the default clink configuration. I don't think there are any meaningful downsides but, admittedly, I don't have very thorough knowledge of cmder or clink.
For completeness, here is my windows terminal profile for cmder:
{
"commandline": "cmd.exe /k \"%cmder_root%\\vendor\\init.bat\"",
"guid": "{40b5c547-9df2-4bf6-9840-1331939523e9}",
"hidden": false,
"icon": "%cmder_root%\\icons\\cmder_green.ico",
"name": "cmder",
"startingDirectory": "~"
}
I mostly only use cmder with cmd, so I'm not sure if cmder+powershell or others need something similar to work in windows terminal also.
How to reproduce
- Open a cmder tab in windows terminal.
cd appdata
or some other directory.- ctrl+shift+D to duplicate tab.
- note that the new tab starts in the original directory.
Additional context
No response
Checklist
- I have read the documentation.
- I have searched for similar issues and found none that describe my issue.
- I have reproduced the issue on the latest version of Cmder.
- I am certain my issues are not related to ConEmu, Clink, or other third-party tools that Cmder uses.
I'm the maintainer of Clink.
For me, in Windows Terminal, "Duplicate Tab" doesn't by default make most shells use the original tab's current directory.
None of these:
- cmd
- powershell core
- bash (from Git for Windows)
- bash in WSL (Ubuntu)
- fish in WSL (Ubuntu)
- zsh in WSL (Ubuntu)
But it does work by default with nushell.
In the Cmder sources, none of the shell customizations seem to mention ]9;9
so I'm not sure why it's working for you everywhere except Cmd/Cmder. Maybe you already had prompt customizations in all the other shells, but not yet in Clink?
The OSC9;9
code seems to be pretty widely accepted as always meaning "tell the terminal what the current directory is", but I'm not confident enough to make Clink always send that.
But I will make Clink send OSC9;9
when the current terminal is Windows Terminal or ConEmu, since both of those terminals do indeed interpret OSC9;9
that way.
I don't think this is something that Cmder should have to do manually in a script. For example, you (and other users) want this to work no matter which custom prompt theme is currently applied, not just when Cmder's default prompt theme is applied.
When Clink v1.8.3 is published, it will automatically include OSC9;9
when hosted in Windows Terminal or ConEmu.
For bookkeeping purposes, this issue should be marked as a Feature Request, not a Bug.
@chrisant996 Excellent implementation 👌🏻 Thanks for the fast update
@ABillBlakely Thanks for the feature request, the prompt filter, as well the instructions! ❤️
A couple of short notes:
1. When Clink v1.8.3 is published, it will automatically include
OSC9;9
when hosted in Windows Terminal or ConEmu.
@ABillBlakely Until the next version of Cmder is released, you can run clink update
to get the latest version of clink installed in your current Cmder installation.
(The CI would pull the latest version of Clink into our repo, so Cmder's Clink version always gets automatically updated to the latest version in the Git repo.)
2. [...] I will make Clink send
OSC9;9
when the current terminal is Windows Terminal or ConEmu, since both of those terminals do indeed interpretOSC9;9
that way.
@chrisant996 Solid choice 👍🏻 I believe this approach is excellent, and I'll try to replicate it for PowerShell as well.
3. [...] not sure if cmder+powershell or others need something similar to work in windows terminal also.
@ABillBlakely Could you please test it out when this is also added in PowerShell for Cmder?
Tip
You can quickly open a PowerShell profile in Cmder just by typing pwsh
.
It's an alias that launches the Cmder profile for PowerShell.
4. Maybe [@ABillBlakely] already had prompt customizations in all the other shells, but not yet in Clink?
If that is the case, I would appreciate it if you could share those customizations, so we could apply them in Cmder.
5. I have mostly successfully configured cmder to work within windows terminal. I set this up manually following the guide with a user install of windows terminal.
@ABillBlakely I see that your current WT profile for Cmder resembles our official integration guide here:
https://github.com/cmderdev/cmder/wiki/Seamless-Windows-Terminal-Integration
Could you please review and compare our documentation against your current setup? We would appreciate it if you could please see if there are any differences between your setup and our docs, and potentially contribute to the Wiki, if there is room for improvements.
Lastly, if you could please vote for Windows Terminal as your preferred terminal emulator for Cmder over at our discussions page, I would appreciate it
https://github.com/orgs/cmderdev/discussions/2864
Thank you @chrisant996 and @DRSDavidSoft for the fast response.
Rolling this into clink is a great solution.
For me, in Windows Terminal, "Duplicate Tab" doesn't by default make most shells use the original tab's current directory.
I must have run microsoft's instructions before I checked with cmd. I had assumed windows terminal implemented this for the default shells but this is not the case. Powershell does not duplicate while preserving paths since I never configured the pwsh prompt.
If that is the case, I would appreciate it if you could share those customizations, so we could apply them in Cmder.
I don't have any clink filters beyond what cmder ships with and I think I only toggled a couple options in the user cmder_prompt_config.lua. I only recently started looking at customizing clink and this is the first time writing a filter.
Could you please review and compare our documentation against your current setup?
That is the guide I used, I believe. Any changes my personal preferences. I will look at contributing in the future if I do anything neat.
For me, in Windows Terminal, "Duplicate Tab" doesn't by default make most shells use the original tab's current directory.
I must have run microsoft's instructions before I checked with cmd. I had assumed windows terminal implemented this for the default shells but this is not the case. Powershell does not duplicate while preserving paths since I never configured the pwsh prompt.
Great, thanks for checking and clarifying!
Copying the current directory is something Windows Terminal can only do if the shell explicitly helps it, and very few shells do that by default. Shells and terminals typically rely on users customizing prompts to get those kind of integration features.