mirror of
https://github.com/nushell/nushell.git
synced 2024-12-21 14:42:07 +01:00
let prompt env vars take strings (#790)
* let prompt env vars take strings * clippy * clippy
This commit is contained in:
parent
91883bd572
commit
ac07d93b02
@ -1,8 +1,9 @@
|
|||||||
use nu_cli::NushellPrompt;
|
use nu_cli::NushellPrompt;
|
||||||
use nu_engine::eval_block;
|
use nu_engine::eval_block;
|
||||||
|
use nu_parser::parse;
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
engine::{EngineState, Stack},
|
engine::{EngineState, Stack, StateWorkingSet},
|
||||||
Config, PipelineData, Span,
|
Config, PipelineData, Span, Value,
|
||||||
};
|
};
|
||||||
use reedline::Prompt;
|
use reedline::Prompt;
|
||||||
|
|
||||||
@ -55,8 +56,8 @@ fn get_prompt_string(
|
|||||||
) -> Option<String> {
|
) -> Option<String> {
|
||||||
stack
|
stack
|
||||||
.get_env_var(engine_state, prompt)
|
.get_env_var(engine_state, prompt)
|
||||||
.and_then(|v| v.as_block().ok())
|
.and_then(|v| match v {
|
||||||
.and_then(|block_id| {
|
Value::Block { val: block_id, .. } => {
|
||||||
let block = engine_state.get_block(block_id);
|
let block = engine_state.get_block(block_id);
|
||||||
eval_block(
|
eval_block(
|
||||||
engine_state,
|
engine_state,
|
||||||
@ -65,6 +66,19 @@ fn get_prompt_string(
|
|||||||
PipelineData::new(Span::new(0, 0)), // Don't try this at home, 0 span is ignored
|
PipelineData::new(Span::new(0, 0)), // Don't try this at home, 0 span is ignored
|
||||||
)
|
)
|
||||||
.ok()
|
.ok()
|
||||||
|
}
|
||||||
|
Value::String { val: source, .. } => {
|
||||||
|
let mut working_set = StateWorkingSet::new(engine_state);
|
||||||
|
let (block, _) = parse(&mut working_set, None, source.as_bytes(), true);
|
||||||
|
eval_block(
|
||||||
|
engine_state,
|
||||||
|
stack,
|
||||||
|
&block,
|
||||||
|
PipelineData::new(Span::new(0, 0)), // Don't try this at home, 0 span is ignored
|
||||||
|
)
|
||||||
|
.ok()
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
})
|
})
|
||||||
.and_then(|pipeline_data| pipeline_data.collect_string("", config).ok())
|
.and_then(|pipeline_data| pipeline_data.collect_string("", config).ok())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user