mirror of
https://github.com/nushell/nushell.git
synced 2025-05-08 20:14:26 +02:00
add history session command (#6587)
This commit is contained in:
parent
0b9dd87ca8
commit
71844755e5
@ -469,13 +469,12 @@ fn variables_completions() {
|
|||||||
// Test completions for $nu
|
// Test completions for $nu
|
||||||
let suggestions = completer.complete("$nu.", 4);
|
let suggestions = completer.complete("$nu.", 4);
|
||||||
|
|
||||||
assert_eq!(10, suggestions.len());
|
assert_eq!(9, suggestions.len());
|
||||||
|
|
||||||
let expected: Vec<String> = vec![
|
let expected: Vec<String> = vec![
|
||||||
"config-path".into(),
|
"config-path".into(),
|
||||||
"env-path".into(),
|
"env-path".into(),
|
||||||
"history-path".into(),
|
"history-path".into(),
|
||||||
"history-session-id".into(),
|
|
||||||
"home-path".into(),
|
"home-path".into(),
|
||||||
"loginshell-path".into(),
|
"loginshell-path".into(),
|
||||||
"os-info".into(),
|
"os-info".into(),
|
||||||
@ -490,13 +489,9 @@ fn variables_completions() {
|
|||||||
// Test completions for $nu.h (filter)
|
// Test completions for $nu.h (filter)
|
||||||
let suggestions = completer.complete("$nu.h", 5);
|
let suggestions = completer.complete("$nu.h", 5);
|
||||||
|
|
||||||
assert_eq!(3, suggestions.len());
|
assert_eq!(2, suggestions.len());
|
||||||
|
|
||||||
let expected: Vec<String> = vec![
|
let expected: Vec<String> = vec!["history-path".into(), "home-path".into()];
|
||||||
"history-path".into(),
|
|
||||||
"history-session-id".into(),
|
|
||||||
"home-path".into(),
|
|
||||||
];
|
|
||||||
|
|
||||||
// Match results
|
// Match results
|
||||||
match_suggestions(expected, suggestions);
|
match_suggestions(expected, suggestions);
|
||||||
|
@ -138,6 +138,7 @@ pub fn create_default_context() -> EngineState {
|
|||||||
bind_command! {
|
bind_command! {
|
||||||
History,
|
History,
|
||||||
Tutor,
|
Tutor,
|
||||||
|
HistorySession,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Path
|
// Path
|
||||||
|
43
crates/nu-command/src/misc/history_session.rs
Normal file
43
crates/nu-command/src/misc/history_session.rs
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
use nu_protocol::ast::Call;
|
||||||
|
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||||
|
use nu_protocol::{Category, Example, IntoPipelineData, PipelineData, Signature, Value};
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct HistorySession;
|
||||||
|
|
||||||
|
impl Command for HistorySession {
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
"history session"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn usage(&self) -> &str {
|
||||||
|
"Get the command history session"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn signature(&self) -> nu_protocol::Signature {
|
||||||
|
Signature::build("history session").category(Category::Misc)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn examples(&self) -> Vec<Example> {
|
||||||
|
vec![Example {
|
||||||
|
example: "history session",
|
||||||
|
description: "Get current history session",
|
||||||
|
result: None,
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run(
|
||||||
|
&self,
|
||||||
|
engine_state: &EngineState,
|
||||||
|
_stack: &mut Stack,
|
||||||
|
call: &Call,
|
||||||
|
_input: PipelineData,
|
||||||
|
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||||
|
Ok(Value::Record {
|
||||||
|
cols: vec!["session-id".into()],
|
||||||
|
vals: vec![Value::int(engine_state.history_session_id, call.head)],
|
||||||
|
span: call.head,
|
||||||
|
}
|
||||||
|
.into_pipeline_data())
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,7 @@
|
|||||||
mod history;
|
mod history;
|
||||||
|
mod history_session;
|
||||||
mod tutor;
|
mod tutor;
|
||||||
|
|
||||||
pub use history::History;
|
pub use history::History;
|
||||||
|
pub use history_session::HistorySession;
|
||||||
pub use tutor::Tutor;
|
pub use tutor::Tutor;
|
||||||
|
@ -1434,9 +1434,6 @@ pub fn eval_variable(
|
|||||||
output_cols.push("os-info".into());
|
output_cols.push("os-info".into());
|
||||||
output_vals.push(os_record);
|
output_vals.push(os_record);
|
||||||
|
|
||||||
output_cols.push("history-session-id".into());
|
|
||||||
output_vals.push(Value::int(engine_state.history_session_id, span));
|
|
||||||
|
|
||||||
Ok(Value::Record {
|
Ok(Value::Record {
|
||||||
cols: output_cols,
|
cols: output_cols,
|
||||||
vals: output_vals,
|
vals: output_vals,
|
||||||
|
Loading…
Reference in New Issue
Block a user