cmderdev / cmderdev/cmder

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

Open
#3,024 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

👆 clink 💬 Type: Guide 🛠 Type: Feature Request
Dominant language
PowerShell
Stars
27k
Forks
2.1k
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Cmder's default Clink configuration and reproduce the issue in a Windows Terminal cmder profile using the listed Ctrl+Shift+D steps. Compare the suggested Lua prompt-filter behavior with the existing configuration; done means duplicated or split tabs preserve the current working directory without changing the prompt appearance.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, powershell
Domain
cli
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.