Skip to content

[Feature Request] Duplicate directory does not work properly in Windows Terminal. Suggest Clink lua addition to fix. #3024

@ABillBlakely

Description

@ABillBlakely

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

  1. Open a cmder tab in windows terminal.
  2. cd appdata or some other directory.
  3. ctrl+shift+D to duplicate tab.
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions