diff --git a/src/ops/show.rs b/src/ops/show.rs index 0d3d41c0ab..3c1d82e849 100644 --- a/src/ops/show.rs +++ b/src/ops/show.rs @@ -66,16 +66,25 @@ fn editor(file: &Path, maybe_line: Option) -> Option { fn parse_editor_command(editor: &str, file: &str, maybe_line: Option) -> Command { let args = &editor.split_whitespace().collect::>(); + + let version = String::from_utf8( + Command::new(args[0]) + .arg("--version") + .output() + .expect("failed to get version via '--version'") + .stdout, + ) + .unwrap(); + + log::info!("editor --version: {:?}", &version); + let mut cmd = Command::new(args[0]); cmd.args(&args[1..]); - let lower = args[0].to_lowercase(); - if let Some(line) = maybe_line { - if lower.ends_with("vi") - || lower.ends_with("vim") - || lower.ends_with("nvim") - || lower.ends_with("nano") + if version.trim_start().starts_with("VIM") + || version.trim_start().starts_with("NVIM") + || version.trim_start().starts_with("GNU nano") { cmd.args([&format!("+{}", line), file]); } else { @@ -86,18 +95,3 @@ fn parse_editor_command(editor: &str, file: &str, maybe_line: Option) -> Co } cmd } - -#[cfg(test)] -mod tests { - use std::ffi::OsStr; - - #[test] - fn parse_editor_command_test() { - let cmd = super::parse_editor_command("/bin/nAnO -f", "README.md", Some(42)); - assert_eq!(cmd.get_program(), OsStr::new("/bin/nAnO")); - assert_eq!( - &cmd.get_args().collect::>(), - &["-f", "+42", "README.md"] - ); - } -}