refactor 'run_edit_command'

This commit is contained in:
steven-omaha
2023-02-15 12:10:01 +01:00
parent 817c5af84e
commit 4252f6b1dd
2 changed files with 33 additions and 20 deletions
+7 -3
View File
@@ -1,19 +1,23 @@
use std::path::PathBuf;
use std::path::Path;
use std::process::{Command, ExitStatus};
use anyhow::{anyhow, Context, Result};
use crate::env::get_editor;
pub fn run_edit_command(files: &[PathBuf]) -> Result<ExitStatus> {
pub fn run_edit_command<P>(files: &[P]) -> Result<ExitStatus>
where
P: for<'a> AsRef<&'a Path>,
{
let mut cmd = Command::new(get_editor().context("getting suitable editor")?);
cmd.current_dir(
files[0]
.as_ref()
.parent()
.context("getting parent dir of first file argument")?,
);
for f in files {
cmd.arg(f.to_string_lossy().to_string());
cmd.arg(f.as_ref().to_string_lossy().to_string());
}
cmd.status().map_err(|e| anyhow!(e))
}