Skip to content

make vim work #1641

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions src/components/externaleditor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,43 @@ impl ExternalEditorComponent {

args.push(path.as_os_str());

Command::new(command.clone())
.current_dir(work_dir)
let exec_result = Command::new(command.clone())
.current_dir(work_dir.clone())
.args(args)
.status()
.map_err(|e| anyhow!("\"{}\": {}", command, e))?;
.status();

if cfg!(windows) {
// if command failed to run on windows retry as a batch file (.bat, .cmd,...)
if exec_result.is_err() {
let cmd_string =
format!("/C {} {}", command, path.display());
let exec_result2 = Command::new("cmd")
.current_dir(work_dir)
.arg(cmd_string)
.status();

match exec_result2 {
// failed to start (unlikely as cmd would have to be missing)
Err(e) => bail!("\"{}\": {}", command, e),

// ran, did it complete OK?
Ok(stat) => {
// no result is treated as arbitrary failure code of 99
let code = stat.code().unwrap_or(99);
if code != 0 {
bail!(
"\"{}\": cmd.exe returned {}",
command,
code
)
}
}
};
}
} else {
exec_result
.map_err(|e| anyhow!("\"{}\": {}", command, e))?;
}

Ok(())
}
Expand Down