Skip to content
Merged
Next Next commit
feat: add option to configure environment variable for edit command
  • Loading branch information
Subjective committed Sep 8, 2023
commit 28c36131e347dda08c77488c2627f02eb2456b2b
13 changes: 13 additions & 0 deletions src/cmds/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,21 @@ impl Command for EditCommand {
args.extend_from_slice(&editor_args);
}

let editor_env = &conf.code.editor_env;
let mut env: Vec<&str> = vec!["", ""];
if !editor_env.is_empty() {
env = editor_env.splitn(2, '=').collect();
if env.len() != 2 {
return Err(crate::Error::FeatureError(
"Invalid environment variable, please check your configuration for errors"
.into(),
));
}
}

args.push(path);
std::process::Command::new(conf.code.editor)
.env(env[0], env[1])
.args(args)
.status()?;
Ok(())
Expand Down
3 changes: 3 additions & 0 deletions src/config/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub struct Code {
#[serde(rename(serialize = "editor-args"), alias = "editor-args", default)]
pub editor_args: Option<Vec<String>>,
#[serde(default, skip_serializing)]
pub editor_env: String,
#[serde(default, skip_serializing)]
pub edit_code_marker: bool,
#[serde(default, skip_serializing)]
pub start_marker: String,
Expand Down Expand Up @@ -44,6 +46,7 @@ impl Default for Code {
Self {
editor: "vim".into(),
editor_args: None,
editor_env: "".into(),
edit_code_marker: false,
start_marker: "".into(),
end_marker: "".into(),
Expand Down