diff --git a/crates/radicle-term/src/editor.rs b/crates/radicle-term/src/editor.rs index 8b4085b4..6c17d32c 100644 --- a/crates/radicle-term/src/editor.rs +++ b/crates/radicle-term/src/editor.rs @@ -227,16 +227,31 @@ fn default_editor() -> Option { if exists("nano") { return Some("nano".into()); } + + // On Windows, `edit` is available by default, see . + #[cfg(windows)] + if exists("edit.exe") { + return Some("edit.exe".into()); + } + + // On Windows, `notepad` is commonly available for decades, see . + #[cfg(windows)] + if exists("notepad.exe") { + return Some("notepad.exe".into()); + } + // If all else fails, we try `vi`. It's usually installed on most unix-based systems. if exists("vi") { return Some("vi".into()); } + None } -/// Check whether a binary can be found in the most common paths. -/// We don't bother checking the $PATH variable, as we're only looking for very standard tools +/// Check whether a binary can be found in the most common paths on Unix-like systems. +/// We don't bother checking the `$PATH` variable, as we're only looking for very standard tools /// and prefer not to make this too complex. +#[cfg(unix)] fn exists(cmd: &str) -> bool { // Some common paths where system-installed binaries are found. const PATHS: &[&str] = &["/usr/local/bin", "/usr/bin", "/bin"]; @@ -248,3 +263,17 @@ fn exists(cmd: &str) -> bool { } false } + +/// Check whether a binary can be found on `$PATH`. +/// See: +/// - +/// - +#[cfg(windows)] +fn exists(cmd: &str) -> bool { + std::process::Command::new("where.exe") + .arg("/q") + .arg("$PATH:".to_owned() + cmd) + .output() + .map(|output| output.status.success()) + .unwrap_or_default() +}