diff options
| author | sigoden <sigoden@gmail.com> | 2024-06-17 10:59:59 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-17 10:59:59 +0800 |
| commit | 189f2271bcc6f841264cb960e35e78c870663645 (patch) | |
| tree | 88dfcce749695668582c05bdc024b1a39ffc06e5 /src/utils | |
| parent | 72e689fab0b414ea943c300c3eb92901c77ce775 (diff) | |
| download | aichat-189f2271bcc6f841264cb960e35e78c870663645.tar.gz | |
feat: add `.edit session` repl command (#606)
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/command.rs | 8 |
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(()) +} |
