mirror of
https://github.com/nushell/nushell
synced 2024-12-27 05:23:11 +00:00
Add CMD_DURATION_MS (#794)
This commit is contained in:
parent
846a048bba
commit
f44954da68
1 changed files with 15 additions and 3 deletions
18
src/repl.rs
18
src/repl.rs
|
@ -1,6 +1,9 @@
|
||||||
use std::sync::{
|
use std::{
|
||||||
atomic::{AtomicBool, Ordering},
|
sync::{
|
||||||
Arc,
|
atomic::{AtomicBool, Ordering},
|
||||||
|
Arc,
|
||||||
|
},
|
||||||
|
time::Instant,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{config_files, prompt_update, reedline_config};
|
use crate::{config_files, prompt_update, reedline_config};
|
||||||
|
@ -165,6 +168,7 @@ pub(crate) fn evaluate(ctrlc: Arc<AtomicBool>, engine_state: &mut EngineState) -
|
||||||
let input = line_editor.read_line(prompt);
|
let input = line_editor.read_line(prompt);
|
||||||
match input {
|
match input {
|
||||||
Ok(Signal::Success(s)) => {
|
Ok(Signal::Success(s)) => {
|
||||||
|
let start_time = Instant::now();
|
||||||
let tokens = lex(s.as_bytes(), 0, &[], &[], false);
|
let tokens = lex(s.as_bytes(), 0, &[], &[], false);
|
||||||
// Check if this is a single call to a directory, if so auto-cd
|
// Check if this is a single call to a directory, if so auto-cd
|
||||||
let cwd = nu_engine::env::current_dir_str(engine_state, &stack)?;
|
let cwd = nu_engine::env::current_dir_str(engine_state, &stack)?;
|
||||||
|
@ -234,6 +238,14 @@ pub(crate) fn evaluate(ctrlc: Arc<AtomicBool>, engine_state: &mut EngineState) -
|
||||||
&s,
|
&s,
|
||||||
&format!("entry #{}", entry_num),
|
&format!("entry #{}", entry_num),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
stack.add_env_var(
|
||||||
|
"CMD_DURATION_MS".into(),
|
||||||
|
Value::String {
|
||||||
|
val: format!("{}", start_time.elapsed().as_millis()),
|
||||||
|
span: Span { start: 0, end: 0 },
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// FIXME: permanent state changes like this hopefully in time can be removed
|
// FIXME: permanent state changes like this hopefully in time can be removed
|
||||||
// and be replaced by just passing the cwd in where needed
|
// and be replaced by just passing the cwd in where needed
|
||||||
|
|
Loading…
Reference in a new issue