forked from extern/nushell
let alias
list aliases (#6717)
* let `alias` list aliases * fix highlighting * Update parse_keywords.rs
This commit is contained in:
parent
868d94f573
commit
5849e4f6e3
@ -62,3 +62,14 @@ fn alias_fails_with_invalid_name() {
|
|||||||
.err
|
.err
|
||||||
.contains("alias name can't be a number or a filesize"));
|
.contains("alias name can't be a number or a filesize"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn alias_alone_lists_aliases() {
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: ".", pipeline(
|
||||||
|
r#"
|
||||||
|
alias a = 3; alias
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
assert!(actual.out.contains("alias") && actual.out.contains("expansion"));
|
||||||
|
}
|
||||||
|
@ -2,7 +2,7 @@ use nu_path::canonicalize_with;
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::{
|
ast::{
|
||||||
Argument, Block, Call, Expr, Expression, ImportPattern, ImportPatternHead,
|
Argument, Block, Call, Expr, Expression, ImportPattern, ImportPatternHead,
|
||||||
ImportPatternMember, Pipeline,
|
ImportPatternMember, PathMember, Pipeline,
|
||||||
},
|
},
|
||||||
engine::{StateWorkingSet, DEFAULT_OVERLAY_NAME},
|
engine::{StateWorkingSet, DEFAULT_OVERLAY_NAME},
|
||||||
span, BlockId, Exportable, Module, PositionalArg, Span, Spanned, SyntaxShape, Type,
|
span, BlockId, Exportable, Module, PositionalArg, Span, Spanned, SyntaxShape, Type,
|
||||||
@ -544,6 +544,51 @@ pub fn parse_alias(
|
|||||||
spans: &[Span],
|
spans: &[Span],
|
||||||
expand_aliases_denylist: &[usize],
|
expand_aliases_denylist: &[usize],
|
||||||
) -> (Pipeline, Option<ParseError>) {
|
) -> (Pipeline, Option<ParseError>) {
|
||||||
|
// if the call is "alias", turn it into "print $nu.scope.aliases"
|
||||||
|
if spans.len() == 1 {
|
||||||
|
let head = Expression {
|
||||||
|
expr: Expr::Var(nu_protocol::NU_VARIABLE_ID),
|
||||||
|
span: Span::new(0, 0),
|
||||||
|
ty: Type::Any,
|
||||||
|
custom_completion: None,
|
||||||
|
};
|
||||||
|
let tail = vec![
|
||||||
|
PathMember::String {
|
||||||
|
val: "scope".to_string(),
|
||||||
|
span: Span::new(0, 0),
|
||||||
|
},
|
||||||
|
PathMember::String {
|
||||||
|
val: "aliases".to_string(),
|
||||||
|
span: Span::new(0, 0),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
let expr = Expression {
|
||||||
|
ty: Type::Any,
|
||||||
|
expr: Expr::FullCellPath(Box::new(nu_protocol::ast::FullCellPath { head, tail })),
|
||||||
|
span: Span::new(0, 0),
|
||||||
|
custom_completion: None,
|
||||||
|
};
|
||||||
|
if let Some(decl_id) = working_set.find_decl(b"print", &Type::Any) {
|
||||||
|
let print_call = Expr::Call(Box::new(Call {
|
||||||
|
head: spans[0],
|
||||||
|
arguments: vec![Argument::Positional(expr)],
|
||||||
|
decl_id,
|
||||||
|
redirect_stdout: true,
|
||||||
|
redirect_stderr: false,
|
||||||
|
}));
|
||||||
|
return (
|
||||||
|
Pipeline::from_vec(vec![Expression {
|
||||||
|
expr: print_call,
|
||||||
|
span: spans[0],
|
||||||
|
ty: Type::Any,
|
||||||
|
custom_completion: None,
|
||||||
|
}]),
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return (Pipeline::from_vec(vec![expr]), None);
|
||||||
|
}
|
||||||
|
|
||||||
let (name_span, alias_name, split_id) =
|
let (name_span, alias_name, split_id) =
|
||||||
if spans.len() > 1 && working_set.get_span_contents(spans[0]) == b"export" {
|
if spans.len() > 1 && working_set.get_span_contents(spans[0]) == b"export" {
|
||||||
(spans[1], spans.get(2), 2)
|
(spans[1], spans.get(2), 2)
|
||||||
|
Loading…
Reference in New Issue
Block a user