add history session command (#6587)

This commit is contained in:
Darren Schroeder
2022-09-19 14:30:04 -05:00
committed by GitHub
parent 0b9dd87ca8
commit 71844755e5
5 changed files with 49 additions and 11 deletions

View File

@ -138,6 +138,7 @@ pub fn create_default_context() -> EngineState {
bind_command! {
History,
Tutor,
HistorySession,
};
// Path

View 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())
}
}

View File

@ -1,5 +1,7 @@
mod history;
mod history_session;
mod tutor;
pub use history::History;
pub use history_session::HistorySession;
pub use tutor::Tutor;