1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use nu_engine::env_to_strings;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, Spanned,
};
use crate::ExternalCommand;
use super::utils::get_editor;
#[derive(Clone)]
pub struct ConfigNu;
impl Command for ConfigNu {
fn name(&self) -> &str {
"config nu"
}
fn signature(&self) -> Signature {
Signature::build(self.name()).category(Category::Env)
}
fn usage(&self) -> &str {
"Edit nu configurations"
}
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "allow user to open and update nu config",
example: "config nu",
result: None,
}]
}
fn run(
&self,
engine_state: &EngineState,
stack: &mut Stack,
_call: &Call,
input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
let env_vars_str = env_to_strings(engine_state, stack)?;
let mut config_path = match nu_path::config_dir() {
Some(path) => path,
None => {
return Err(ShellError::GenericError(
"Could not find nu config path".to_string(),
"Could not find nu config path".to_string(),
None,
None,
Vec::new(),
));
}
};
config_path.push("nushell");
let mut nu_config = config_path.clone();
nu_config.push("config.nu");
let name = Spanned {
item: get_editor(engine_state, stack),
span: Span { start: 0, end: 0 },
};
let args = vec![Spanned {
item: nu_config.to_string_lossy().to_string(),
span: Span { start: 0, end: 0 },
}];
let command = ExternalCommand {
name,
args,
redirect_stdout: false,
redirect_stderr: false,
env_vars: env_vars_str,
};
command.run_with_input(engine_state, stack, input)
}
}