Skip to content

Commit

Permalink
Fall back to notepad on Windows
Browse files Browse the repository at this point in the history
Summary: Should be a safe fallback, and users can still configure EDITOR however they like.

Reviewed By: robarnold, akrieger

Differential Revision: D7936333

fbshipit-source-id: f9abb41893183f6d3b7706c725340b60c1055b51
  • Loading branch information
swolchok authored and facebook-github-bot committed May 10, 2018
1 parent ce54559 commit 2502ae1
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,25 @@ fn slurp(path: &Path) -> Result<String> {
fn run_editor(path: &Path, start_line: usize) -> Result<()> {
let editor = env::var("EDITOR").unwrap_or(String::from("vim"));
let args: Vec<&str> = editor.split(" ").collect();
Command::new(args[0])
.args(&args[1..])
.arg(format!("+{}", start_line))
.arg(path)
.spawn()
.with_context(|_| format!("Unable to launch editor {} on path {:?}", editor, path))?
let mut editor_cmd = {
let mut cmd = Command::new(args[0])
.args(&args[1..])
.arg(format!("+{}", start_line))
.arg(path)
.spawn()
.with_context(|_| format!("Unable to launch editor {} on path {:?}", editor, path));
if cfg!(target_os = "windows") && cmd.is_err() {
// Windows-only fallback to notepad.exe.
cmd = Command::new("notepad.exe")
.arg(path)
.spawn()
.with_context(|_| {
format!("Unable to launch editor notepad.exe on path {:?}", path)
});
}
cmd?
};
editor_cmd
.wait()
.context("Error waiting for editor to exit")?;
Ok(())
Expand Down

0 comments on commit 2502ae1

Please sign in to comment.