-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Windows Terminal CWD Shell integration (OSC 9;9;) #10166
Comments
IIRC, we send OSC7 on every new prompt if shell_integration is enabled. I wouldn't want to shell out to wslpath on every prompt. I'd be interested if you plan on sending both OSC7 and OSC9 on each prompt? I think we'd probably be up for this, but we need to talk it through, either here or in Discord #design-discussion channel. |
Regarding that it happens on every prompt you're right as it happens on every loop of the repl. Meanwhile, I've started the discussion in Discord |
I found another enhancement related to wsl - #6436 that could be done by using wslpath too. |
As a rule of thumb, I don't like shelling out for anything as it causes performance problems. Depending on the implementation, I could be convinced to ignore that rule. Before calling out to
I found this that may be helpful. There may be other usages on github that may be more helpful. I just did a quick search. So, if you want to take a swing at a PR, I'm up for it too. |
I'll try to work on this when I have time. Thanks for referencing example implementation. Current points I'm considering to make it efficient as much as possible:
If anyone has any additional thoughts, please spit them out. |
Hey guys, not very proficient in the nu language, how would I implement shell integration for nushell like the powershell prompt in the links below? (assuming a normal windows machine without wsl) https://learn.microsoft.com/en-us/windows/terminal/tutorials/shell-integration https://devblogs.microsoft.com/commandline/shell-integration-in-the-windows-terminal/ (the links above are old, this feature is available on stable Windows Terminal builds, not only preview builds) |
@Araxeus I'd start by using nushell 0.94.0 and enabling the particular shell integration feature you wish to have from the nushell config.nu. 9;9 is implemented now so closing this issue. |
Looks like you don't have something setup right. I'd guess how WT is launching nushell. I have all the shell_integration items enabled and don't have issues with nushell. |
I get something similar with duplicate tab. Could be a bug, not sure. |
yup, it's a bug. i see it here.
|
Also, by default, it won't work for WSL tabs without wslpath conversion compared to the hook from the description. |
I'm not sure of all of the magic that is in wslpath. I wonder if it's open source? |
no, it's a built-in tool in WSL. Another option could be to try open-source alternatives and I saw only this one for rust |
I can't get that one working. |
# Description This fixes a bug in the `OSC 9;9` functionality where the path wasn't being constructed properly and therefore wasn't getting set right for things like "Duplicate Tab" in Windows Terminal. Thanks to @Araxeus for finding it. Related to #10166 # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
It looks like shelling out to wslpath may be the best way to do this for WSL but it's kind of niche, so I'm not sure it's worth it. |
After looking at this for a few hours, the version of WSL2 that I have is terribly buggy wrt OSC 9;9. I can't upgrade right now. So, this will have to wait. Just to document some debug code and what I was doing, here it is. fn run_shell_integration_osc9_9(engine_state: &EngineState, stack: &mut Stack, use_color: bool) {
#[allow(deprecated)]
if let Ok(path) = current_dir_str(engine_state, stack) {
let start_time = Instant::now();
// Let's check to see if we're in Microsoft's WSL
let wsl_distro = engine_state
.get_env_var("WSL_DISTRO_NAME")
.map_or("NO_DISTRO".into(), |v| {
v.to_expanded_string("", engine_state.get_config())
});
if wsl_distro == "NO_DISTRO" {
// Otherwise, communicate the path as OSC 9;9 from ConEmu (often used for spawning new tabs in the same dir)
// This is helpful in Windows Terminal with Duplicate Tab
eprintln!("path: {path}");
run_ansi_sequence(&format!(
"\x1b]9;9;{}\x1b\\",
percent_encoding::utf8_percent_encode(&path, percent_encoding::CONTROLS)
));
} else {
// Otherwise, communicate the path as OSC 9;9 from WSL (often used for spawning new tabs in the same dir)
// This is helpful in Windows Terminal with Duplicate Tab
let wsl_path = format!(
"\\\\wsl.localhost\\{}{}",
wsl_distro,
path.replace("/", "\\")
);
// let wsl_path = format!("\\\\wsl$\\{}{}", wsl_distro, path.replace("/", "\\"));
// let wsl_path = format!("//wsl.localhost/{}{}", wsl_distro, path);
eprintln!("wsl_path: {wsl_path}");
let seq = &format!(
"\x1b]9;9;{}\x1b\\",
percent_encoding::utf8_percent_encode(&wsl_path, percent_encoding::CONTROLS)
);
eprintln!("seq: {:#?}", seq);
run_ansi_sequence(seq);
}
perf(
"communicate path to terminal with osc9;9",
start_time,
file!(),
line!(),
column!(),
use_color,
);
}
} |
Related problem
Windows Terminal for tracking the current dir in shell supports only osc
9;9;
while nushell generates only osc 7 to track the cwd.Describe the solution you'd like
Add output for osc
9;9;
in nushell based on the docs that will allow to track the cwd in Windows Terminal.Also, it should help with shell integration inside Vs Code that currently handles osc 7 differently that prevents from opening new instance completely on windows + nushell.
Describe alternatives you've considered
Users can add custom hook to implement this, e.g.
I've tested this and it works good in Windows Terminal and Vs code integrated terminal. But it requires additional setup from users while Windows Terminal will soon or already become default terminal on Windows.
Additional context and details
I could make pr myself but I wanted to sure it is appropriate to add windows specific shell_integration (though, I believe many windows users will benefit from it). Also, it requires specific treatment for wsl shell i.e. converting path properly - it should be simple using embedded
wslpath
command but is it ok to call some external on every cwd change? (I haven't found any existing solution to convert path without utilizing call to the command)The text was updated successfully, but these errors were encountered: