diff options
author | Cyborus <cyborus@cyborus.xyz> | 2023-12-13 06:25:28 +0100 |
---|---|---|
committer | Cyborus <cyborus@cyborus.xyz> | 2023-12-13 06:25:28 +0100 |
commit | 4a9f52482703e2018c907cac3e01045139b81284 (patch) | |
tree | 0093940ea7fa4475ec10c0a02dda31b23ea763e9 | |
parent | Merge pull request 'add git remote selection flag' (#10) from select-remote i... (diff) | |
download | forgejo-cli-4a9f52482703e2018c907cac3e01045139b81284.tar.xz forgejo-cli-4a9f52482703e2018c907cac3e01045139b81284.zip |
add system for editor-specific flags
-rw-r--r-- | src/main.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index ad62b50..414a161 100644 --- a/src/main.rs +++ b/src/main.rs @@ -70,7 +70,7 @@ async fn readline(msg: &str) -> eyre::Result<String> { } async fn editor(contents: &mut String, ext: Option<&str>) -> eyre::Result<()> { - let editor = std::env::var_os("EDITOR").ok_or_else(|| eyre!("unable to locate editor"))?; + let editor = std::path::PathBuf::from(std::env::var_os("EDITOR").ok_or_else(|| eyre!("unable to locate editor"))?); let (mut file, path) = tempfile(ext).await?; file.write_all(contents.as_bytes()).await?; @@ -80,7 +80,9 @@ async fn editor(contents: &mut String, ext: Option<&str>) -> eyre::Result<()> { // on errors let res = (|| async { eprint!("waiting on editor\r"); + let flags = get_editor_flags(&editor); let status = tokio::process::Command::new(editor) + .args(flags) .arg(&path) .status() .await?; @@ -100,6 +102,17 @@ async fn editor(contents: &mut String, ext: Option<&str>) -> eyre::Result<()> { Ok(()) } +fn get_editor_flags(editor_path: &std::path::Path) -> &'static [&'static str] { + let editor_name = match editor_path.file_stem().and_then(|s| s.to_str()) { + Some(name) => name, + None => return &[], + }; + if editor_name == "code" { + return &["--wait"]; + } + &[] +} + async fn tempfile(ext: Option<&str>) -> tokio::io::Result<(tokio::fs::File, std::path::PathBuf)> { let filename = uuid::Uuid::new_v4(); let mut path = std::env::temp_dir().join(filename.to_string()); |