Skip to content

Commit 28c3613

Browse files
committed
feat: add option to configure environment variable for edit command
1 parent 68d269c commit 28c3613

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/cmds/edit.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,21 @@ impl Command for EditCommand {
161161
args.extend_from_slice(&editor_args);
162162
}
163163

164+
let editor_env = &conf.code.editor_env;
165+
let mut env: Vec<&str> = vec!["", ""];
166+
if !editor_env.is_empty() {
167+
env = editor_env.splitn(2, '=').collect();
168+
if env.len() != 2 {
169+
return Err(crate::Error::FeatureError(
170+
"Invalid environment variable, please check your configuration for errors"
171+
.into(),
172+
));
173+
}
174+
}
175+
164176
args.push(path);
165177
std::process::Command::new(conf.code.editor)
178+
.env(env[0], env[1])
166179
.args(args)
167180
.status()?;
168181
Ok(())

src/config/code.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ pub struct Code {
1717
#[serde(rename(serialize = "editor-args"), alias = "editor-args", default)]
1818
pub editor_args: Option<Vec<String>>,
1919
#[serde(default, skip_serializing)]
20+
pub editor_env: String,
21+
#[serde(default, skip_serializing)]
2022
pub edit_code_marker: bool,
2123
#[serde(default, skip_serializing)]
2224
pub start_marker: String,
@@ -44,6 +46,7 @@ impl Default for Code {
4446
Self {
4547
editor: "vim".into(),
4648
editor_args: None,
49+
editor_env: "".into(),
4750
edit_code_marker: false,
4851
start_marker: "".into(),
4952
end_marker: "".into(),

0 commit comments

Comments
 (0)