mirror of
https://github.com/nushell/nushell.git
synced 2025-02-03 03:59:23 +01:00
Merge branch 'master' into pixel_ascii
This commit is contained in:
commit
49ddfa3940
@ -15,7 +15,7 @@ crate fn dir_entry_dict(
|
||||
) -> Result<Spanned<Value>, ShellError> {
|
||||
let mut dict = SpannedDictBuilder::new(span);
|
||||
let filename = entry.file_name();
|
||||
dict.insert("file name", Value::string(filename.to_string_lossy()));
|
||||
dict.insert("name", Value::string(filename.to_string_lossy()));
|
||||
|
||||
let metadata = entry.metadata()?;
|
||||
|
||||
@ -27,7 +27,7 @@ crate fn dir_entry_dict(
|
||||
FileType::Symlink
|
||||
};
|
||||
|
||||
dict.insert("file type", Value::string(format!("{:?}", kind)));
|
||||
dict.insert("type", Value::string(format!("{:?}", kind)));
|
||||
dict.insert(
|
||||
"readonly",
|
||||
Value::boolean(metadata.permissions().readonly()),
|
||||
|
@ -161,7 +161,7 @@ pub fn baseline_parse_semantic_token(
|
||||
TokenNode::Delimited(delimited) => baseline_parse_delimited(delimited, registry, source),
|
||||
TokenNode::Pipeline(_pipeline) => unimplemented!(),
|
||||
TokenNode::Operator(_op) => unreachable!(),
|
||||
TokenNode::Flag(_flag) => unimplemented!(),
|
||||
TokenNode::Flag(_flag) => Err(ShellError::unimplemented("passing flags is not supported yet.")),
|
||||
TokenNode::Identifier(_span) => unreachable!(),
|
||||
TokenNode::Whitespace(_span) => unreachable!(),
|
||||
TokenNode::Error(error) => Err(*error.item.clone()),
|
||||
|
@ -80,7 +80,7 @@ pub fn raw_integer(input: NomSpan) -> IResult<NomSpan, Spanned<i64>> {
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
/*
|
||||
pub fn integer(input: NomSpan) -> IResult<NomSpan, TokenNode> {
|
||||
trace_step(input, "integer", move |input| {
|
||||
let (input, int) = raw_integer(input)?;
|
||||
@ -88,6 +88,7 @@ pub fn integer(input: NomSpan) -> IResult<NomSpan, TokenNode> {
|
||||
Ok((input, TokenTreeBuilder::spanned_int(*int, int.span)))
|
||||
})
|
||||
}
|
||||
*/
|
||||
|
||||
pub fn operator(input: NomSpan) -> IResult<NomSpan, TokenNode> {
|
||||
trace_step(input, "operator", |input| {
|
||||
@ -217,6 +218,8 @@ pub fn raw_unit(input: NomSpan) -> IResult<NomSpan, Spanned<Unit>> {
|
||||
tag("KB"),
|
||||
tag("kb"),
|
||||
tag("Kb"),
|
||||
tag("K"),
|
||||
tag("k"),
|
||||
tag("MB"),
|
||||
tag("mb"),
|
||||
tag("Mb"),
|
||||
@ -241,22 +244,37 @@ pub fn raw_unit(input: NomSpan) -> IResult<NomSpan, Spanned<Unit>> {
|
||||
|
||||
pub fn size(input: NomSpan) -> IResult<NomSpan, TokenNode> {
|
||||
trace_step(input, "size", move |input| {
|
||||
let mut is_size = false;
|
||||
let start = input.offset;
|
||||
let (input, int) = raw_integer(input)?;
|
||||
let (input, unit) = raw_unit(input)?;
|
||||
if let Ok((input, Some(size))) = opt(raw_unit)(input) {
|
||||
let end = input.offset;
|
||||
|
||||
// Check to make sure there is no trailing parseable characters
|
||||
if let Ok((input, Some(extra))) = opt(bare)(input) {
|
||||
return Err(nom::Err::Error((input, nom::error::ErrorKind::Char)));
|
||||
}
|
||||
|
||||
Ok((
|
||||
input,
|
||||
TokenTreeBuilder::spanned_size((*int, *unit), (start, end)),
|
||||
TokenTreeBuilder::spanned_size((*int, *size), (start, end)),
|
||||
))
|
||||
} else {
|
||||
let end = input.offset;
|
||||
|
||||
// Check to make sure there is no trailing parseable characters
|
||||
if let Ok((input, Some(extra))) = opt(bare)(input) {
|
||||
return Err(nom::Err::Error((input, nom::error::ErrorKind::Char)));
|
||||
}
|
||||
|
||||
Ok((input, TokenTreeBuilder::spanned_int((*int), (start, end))))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn leaf(input: NomSpan) -> IResult<NomSpan, TokenNode> {
|
||||
trace_step(input, "leaf", move |input| {
|
||||
let (input, node) =
|
||||
alt((size, integer, string, operator, flag, shorthand, var, bare))(input)?;
|
||||
let (input, node) = alt((size, string, operator, flag, shorthand, var, bare))(input)?;
|
||||
|
||||
Ok((input, node))
|
||||
})
|
||||
@ -513,6 +531,7 @@ fn int<T>(frag: &str, neg: Option<T>) -> i64 {
|
||||
fn is_start_bare_char(c: char) -> bool {
|
||||
match c {
|
||||
_ if c.is_alphabetic() => true,
|
||||
_ if c.is_numeric() => true,
|
||||
'.' => true,
|
||||
'\\' => true,
|
||||
'/' => true,
|
||||
@ -596,12 +615,12 @@ mod tests {
|
||||
#[test]
|
||||
fn test_integer() {
|
||||
assert_leaf! {
|
||||
parsers [ integer ]
|
||||
parsers [ size ]
|
||||
"123" -> 0..3 { Integer(123) }
|
||||
}
|
||||
|
||||
assert_leaf! {
|
||||
parsers [ integer ]
|
||||
parsers [ size ]
|
||||
"-123" -> 0..4 { Integer(-123) }
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ impl FromStr for Unit {
|
||||
fn from_str(input: &str) -> Result<Self, <Self as std::str::FromStr>::Err> {
|
||||
match input {
|
||||
"B" | "b" => Ok(Unit::B),
|
||||
"KB" | "kb" | "Kb" => Ok(Unit::KB),
|
||||
"KB" | "kb" | "Kb" | "K" | "k" => Ok(Unit::KB),
|
||||
"MB" | "mb" | "Mb" => Ok(Unit::MB),
|
||||
"GB" | "gb" | "Gb" => Ok(Unit::GB),
|
||||
"TB" | "tb" | "Tb" => Ok(Unit::TB),
|
||||
|
@ -23,6 +23,24 @@ impl Completer for NuCompleter {
|
||||
|
||||
let mut completions = self.file_completer.complete(line, pos, context)?.1;
|
||||
|
||||
for completion in &mut completions {
|
||||
if completion.replacement.contains("\\ ") {
|
||||
completion.replacement = completion.replacement.replace("\\ ", " ");
|
||||
}
|
||||
if completion.replacement.contains("\\(") {
|
||||
completion.replacement = completion.replacement.replace("\\(", "(");
|
||||
}
|
||||
|
||||
if completion.replacement.contains(" ") || completion.replacement.contains("(") {
|
||||
if !completion.replacement.starts_with("\"") {
|
||||
completion.replacement = format!("\"{}", completion.replacement);
|
||||
}
|
||||
if !completion.replacement.ends_with("\"") {
|
||||
completion.replacement = format!("{}\"", completion.replacement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let line_chars: Vec<_> = line.chars().collect();
|
||||
let mut replace_pos = pos;
|
||||
while replace_pos > 0 {
|
||||
|
@ -1,4 +1,4 @@
|
||||
cd tests
|
||||
cd dirtest
|
||||
ls | where size > 1kb | get "file name" | trim | echo $it
|
||||
ls | where size > 1kb | get name | trim | echo $it
|
||||
exit
|
Loading…
Reference in New Issue
Block a user