Improve alias highlighting/completions (#3594)

* Improve alias highlighting/completions

* Add example
This commit is contained in:
JT
2021-06-10 13:13:08 +12:00
committed by GitHub
parent 2591050fbe
commit d056bf070f
4 changed files with 50 additions and 10 deletions

View File

@ -4,6 +4,7 @@ pub(crate) mod macros;
mod from_delimited_data;
mod to_delimited_data;
pub(crate) mod alias;
pub(crate) mod all;
pub(crate) mod ansi;
pub(crate) mod any;
@ -145,6 +146,7 @@ pub(crate) mod wrap;
pub(crate) use autoview::Autoview;
pub(crate) use cd::Cd;
pub(crate) use alias::Alias;
pub(crate) use ansi::Ansi;
pub(crate) use ansi::AnsiGradient;
pub(crate) use ansi::AnsiStrip;

View File

@ -0,0 +1,40 @@
use crate::prelude::*;
use nu_engine::WholeStreamCommand;
use nu_errors::ShellError;
use nu_protocol::{Signature, SyntaxShape};
pub struct Alias;
impl WholeStreamCommand for Alias {
fn name(&self) -> &str {
"alias"
}
fn signature(&self) -> Signature {
Signature::build("alias")
.required("name", SyntaxShape::String, "the name of the alias")
.required("equals", SyntaxShape::String, "the equals sign")
.rest(SyntaxShape::Any, "the expansion for the alias")
}
fn usage(&self) -> &str {
"Alias a command to an expansion."
}
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
alias(args)
}
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Alias ll to ls -l",
example: "alias ll = ls -l",
result: None,
}]
}
}
pub fn alias(_: CommandArgs) -> Result<OutputStream, ShellError> {
Ok(OutputStream::empty())
}

View File

@ -16,6 +16,7 @@ pub fn create_default_context(interactive: bool) -> Result<EvaluationContext, Bo
whole_stream_command(LoadEnv),
whole_stream_command(Def),
whole_stream_command(Source),
whole_stream_command(Alias),
// System/file operations
whole_stream_command(Exec),
whole_stream_command(Pwd),