2021-09-29 20:25:05 +02:00
|
|
|
use nu_protocol::ast::Call;
|
2021-10-25 18:58:58 +02:00
|
|
|
use nu_protocol::engine::{Command, EngineState, Stack};
|
2022-11-09 22:55:05 +01:00
|
|
|
use nu_protocol::{Category, Example, PipelineData, Signature, Span, SyntaxShape, Type, Value};
|
2021-09-29 20:25:05 +02:00
|
|
|
|
2021-10-25 06:01:02 +02:00
|
|
|
#[derive(Clone)]
|
2021-09-29 20:25:05 +02:00
|
|
|
pub struct Alias;
|
|
|
|
|
|
|
|
impl Command for Alias {
|
|
|
|
fn name(&self) -> &str {
|
|
|
|
"alias"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn usage(&self) -> &str {
|
|
|
|
"Alias a command (with optional flags) to a new name"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn signature(&self) -> nu_protocol::Signature {
|
|
|
|
Signature::build("alias")
|
2022-11-09 22:55:05 +01:00
|
|
|
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
|
2021-09-29 20:25:05 +02:00
|
|
|
.required("name", SyntaxShape::String, "name of the alias")
|
|
|
|
.required(
|
|
|
|
"initial_value",
|
|
|
|
SyntaxShape::Keyword(b"=".to_vec(), Box::new(SyntaxShape::Expression)),
|
|
|
|
"equals sign followed by value",
|
|
|
|
)
|
2021-11-17 05:22:37 +01:00
|
|
|
.category(Category::Core)
|
2021-09-29 20:25:05 +02:00
|
|
|
}
|
|
|
|
|
2022-03-26 20:22:45 +01:00
|
|
|
fn extra_usage(&self) -> &str {
|
2022-05-26 17:15:36 +02:00
|
|
|
r#"This command is a parser keyword. For details, check:
|
2022-08-17 19:51:07 +02:00
|
|
|
https://www.nushell.sh/book/thinking_in_nu.html"#
|
2022-03-26 20:22:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn is_parser_keyword(&self) -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2022-06-08 13:22:53 +02:00
|
|
|
fn search_terms(&self) -> Vec<&str> {
|
|
|
|
vec!["abbr", "aka", "fn", "func", "function"]
|
|
|
|
}
|
|
|
|
|
2021-09-29 20:25:05 +02:00
|
|
|
fn run(
|
|
|
|
&self,
|
2021-10-25 08:31:39 +02:00
|
|
|
_engine_state: &EngineState,
|
|
|
|
_stack: &mut Stack,
|
2021-11-06 06:50:33 +01:00
|
|
|
call: &Call,
|
2021-10-25 06:01:02 +02:00
|
|
|
_input: PipelineData,
|
|
|
|
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
2021-11-06 06:50:33 +01:00
|
|
|
Ok(PipelineData::new(call.head))
|
2021-09-29 20:25:05 +02:00
|
|
|
}
|
2022-02-18 14:06:52 +01:00
|
|
|
|
|
|
|
fn examples(&self) -> Vec<Example> {
|
2022-10-26 18:36:42 +02:00
|
|
|
vec![
|
|
|
|
Example {
|
|
|
|
description: "Alias ll to ls -l",
|
|
|
|
example: "alias ll = ls -l",
|
2022-11-09 22:55:05 +01:00
|
|
|
result: Some(Value::nothing(Span::test_data())),
|
2022-10-26 18:36:42 +02:00
|
|
|
},
|
|
|
|
Example {
|
|
|
|
description: "Make an alias that makes a list of all custom commands",
|
|
|
|
example: "alias customs = ($nu.scope.commands | where is_custom | get command)",
|
2022-11-09 22:55:05 +01:00
|
|
|
result: Some(Value::nothing(Span::test_data())),
|
2022-10-26 18:36:42 +02:00
|
|
|
},
|
|
|
|
]
|
2022-02-18 14:06:52 +01:00
|
|
|
}
|
2021-09-29 20:25:05 +02:00
|
|
|
}
|