summaryrefslogtreecommitdiffstats
path: root/src/utils/command.rs
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-06-17 10:59:59 +0800
committerGitHub <noreply@github.com>2024-06-17 10:59:59 +0800
commit189f2271bcc6f841264cb960e35e78c870663645 (patch)
tree88dfcce749695668582c05bdc024b1a39ffc06e5 /src/utils/command.rs
parent72e689fab0b414ea943c300c3eb92901c77ce775 (diff)
downloadaichat-189f2271bcc6f841264cb960e35e78c870663645.tar.gz
feat: add `.edit session` repl command (#606)
Diffstat (limited to 'src/utils/command.rs')
-rw-r--r--src/utils/command.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/utils/command.rs b/src/utils/command.rs
index 873e40b..557649a 100644
--- a/src/utils/command.rs
+++ b/src/utils/command.rs
@@ -1,4 +1,4 @@
-use std::{collections::HashMap, env, ffi::OsStr, process::Command};
+use std::{collections::HashMap, env, ffi::OsStr, path::Path, process::Command};
use anyhow::{Context, Result};
@@ -90,3 +90,9 @@ pub fn run_command_with_output<T: AsRef<OsStr>>(
let stderr = std::str::from_utf8(&output.stderr).context("Invalid UTF-8 in stderr")?;
Ok((status.success(), stdout.to_string(), stderr.to_string()))
}
+
+pub fn edit_file(editor: &str, path: &Path) -> Result<()> {
+ let mut child = Command::new(editor).arg(path).spawn()?;
+ child.wait()?;
+ Ok(())
+}