From ac07d93b02bd413c84e7ad21cb785c1ace8f6f5b Mon Sep 17 00:00:00 2001 From: JT <547158+jntrnr@users.noreply.github.com> Date: Thu, 20 Jan 2022 21:22:03 -0500 Subject: [PATCH] let prompt env vars take strings (#790) * let prompt env vars take strings * clippy * clippy --- src/prompt_update.rs | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/prompt_update.rs b/src/prompt_update.rs index 42c2d5a6fc..d7e1be08d1 100644 --- a/src/prompt_update.rs +++ b/src/prompt_update.rs @@ -1,8 +1,9 @@ use nu_cli::NushellPrompt; use nu_engine::eval_block; +use nu_parser::parse; use nu_protocol::{ - engine::{EngineState, Stack}, - Config, PipelineData, Span, + engine::{EngineState, Stack, StateWorkingSet}, + Config, PipelineData, Span, Value, }; use reedline::Prompt; @@ -55,16 +56,29 @@ fn get_prompt_string( ) -> Option { stack .get_env_var(engine_state, prompt) - .and_then(|v| v.as_block().ok()) - .and_then(|block_id| { - let block = engine_state.get_block(block_id); - eval_block( - engine_state, - stack, - block, - PipelineData::new(Span::new(0, 0)), // Don't try this at home, 0 span is ignored - ) - .ok() + .and_then(|v| match v { + Value::Block { val: block_id, .. } => { + let block = engine_state.get_block(block_id); + eval_block( + engine_state, + stack, + block, + PipelineData::new(Span::new(0, 0)), // Don't try this at home, 0 span is ignored + ) + .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()) }