microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.38k stars 28.94k forks source link

`terminal.goToRecentDirectory` is not shell-aware #178994

Open pfitzseb opened 1 year ago

pfitzseb commented 1 year ago

The shell integration feature can be used by arbitrary REPL-like programs. This includes cwd detection. Unfortunately, the current implementation of workbench.action.terminal.goToRecentDirectory can't handle that gracefully, since it seems to always send something like cd $dir\n to the terminal.

This is the status quo in Julia (switching to shell mode makes the command work, but is cumbersome): Peek 2023-04-03 13-16

It would be awesome if REPL-likes could register a template string at startup, which VS Code would then send instead of cd $dir. E.g.

OSC 633 ; P ; cdTemplate='cd("$dir")' ST
Tyriar commented 1 year ago

Good idea 👍. I guess we would also want to consider whether \ or / is preferred and special path mappings like in git bash which would transform c:\Users to /c/Users

Tyriar commented 1 year ago

cc @zadjii-msft

Tyriar commented 1 year ago

I think 633 P is the right sequence here as well since it was intended to set "properties" on the terminal which are a set one time, as opposed to the others which are very common.

zadjii-msft commented 1 year ago

Ha, yes, this just came up in a review I was doing too. link.

cmd is another interesting example, because changing to another drive requires cd /d {path}.

If you do end up doing something like this with a custom property, we can try and follow suite. I'm pretty sure there's an edge case somewhere out there where one shell will accept paths wrapped in single-quotes, and others in double quotes.

I'm also personally not planning on sending the \r at the end of any commands we synthesize from history. So, if we do end up with cd c:\foo on the commandline, someone can go back and edit it first.

Tyriar commented 1 year ago

I'm also personally not planning on sending the \r at the end of any commands we synthesize from history. So, if we do end up with cd c:\foo on the commandline, someone can go back and edit it first.

@zadjii-msft we have a pattern where we don't send the \r if you hold alt fyi:

image image

zadjii-msft commented 1 year ago

Oh that's neat, I'll have to keep that in mind