diff --git a/crates/nu-cli/src/repl.rs b/crates/nu-cli/src/repl.rs index 483f76f31..c05ad95ad 100644 --- a/crates/nu-cli/src/repl.rs +++ b/crates/nu-cli/src/repl.rs @@ -626,19 +626,29 @@ pub fn evaluate_repl( if let Some(cwd) = stack.get_env_var(engine_state, "PWD") { let path = cwd.as_string()?; - // Communicate the path as OSC 7 (often used for spawning new tabs in the same dir) - run_ansi_sequence(&format!( - "\x1b]7;file://{}{}{}\x1b\\", - percent_encoding::utf8_percent_encode( - &hostname.unwrap_or_else(|| "localhost".to_string()), - percent_encoding::CONTROLS - ), - if path.starts_with('/') { "" } else { "/" }, - percent_encoding::utf8_percent_encode( - &path, - percent_encoding::CONTROLS - ) - ))?; + // Supported escape sequences of Microsoft's Visual Studio Code (vscode) + // https://code.visualstudio.com/docs/terminal/shell-integration#_supported-escape-sequences + if stack.get_env_var(engine_state, "TERM_PROGRAM") + == Some(Value::test_string("vscode")) + { + // If we're in vscode, run their specific ansi escape sequence. + // This is helpful for ctrl+g to change directories in the terminal. + run_ansi_sequence(&format!("\x1b]633;P;Cwd={}\x1b\\", path))?; + } else { + // Otherwise, communicate the path as OSC 7 (often used for spawning new tabs in the same dir) + run_ansi_sequence(&format!( + "\x1b]7;file://{}{}{}\x1b\\", + percent_encoding::utf8_percent_encode( + &hostname.unwrap_or_else(|| "localhost".to_string()), + percent_encoding::CONTROLS + ), + if path.starts_with('/') { "" } else { "/" }, + percent_encoding::utf8_percent_encode( + &path, + percent_encoding::CONTROLS + ) + ))?; + } // Try to abbreviate string for windows title let maybe_abbrev_path = if let Some(p) = nu_path::home_dir() {