From 96a1bf5f8d6be24bb4c6c382f2620a8813665ae8 Mon Sep 17 00:00:00 2001 From: JT <547158+jntrnr@users.noreply.github.com> Date: Wed, 2 Mar 2022 19:55:03 -0500 Subject: [PATCH] Experiment: Allow both $true/true and $false/false (#4696) * Change true/false to keywords * oops, clippy * Both kinds of bools * Add in some boolean variables * disable py virtualenv test for now --- .github/workflows/ci.yml | 32 +++++++------- crates/nu-cli/src/completions.rs | 4 +- .../nu-command/src/conversions/into/binary.rs | 2 +- .../nu-command/src/conversions/into/bool.rs | 4 +- crates/nu-command/src/conversions/into/int.rs | 2 +- .../nu-command/src/conversions/into/string.rs | 2 +- crates/nu-command/src/core_commands/debug.rs | 3 +- crates/nu-command/src/core_commands/let_.rs | 2 +- crates/nu-command/src/core_commands/tutor.rs | 2 +- .../src/dataframe/eager/filter_with.rs | 2 +- .../nu-command/src/dataframe/eager/to_df.rs | 2 +- .../src/dataframe/series/all_false.rs | 2 +- .../src/dataframe/series/all_true.rs | 2 +- .../src/dataframe/series/indexes/arg_true.rs | 2 +- .../src/dataframe/series/masks/not.rs | 2 +- crates/nu-command/src/filters/find.rs | 2 +- crates/nu-command/src/filters/shuffle.rs | 2 +- crates/nu-command/src/formats/to/nuon.rs | 4 +- crates/nu-command/src/shells/shells_.rs | 2 +- crates/nu-command/src/viewers/griddle.rs | 2 +- .../tests/commands/str_/into_string.rs | 2 +- .../tests/format_conversions/nuon.rs | 2 +- crates/nu-parser/src/parser.rs | 42 ++++++++++++++++++- docs/How_To_Coloring_and_Theming.md | 10 ++--- docs/commands/debug.md | 2 +- docs/commands/dfr_all-false.md | 2 +- docs/commands/dfr_all-true.md | 2 +- docs/commands/dfr_arg-true.md | 2 +- docs/commands/dfr_filter-with.md | 2 +- docs/commands/dfr_not.md | 2 +- docs/commands/dfr_to-df.md | 2 +- docs/commands/find.md | 2 +- docs/commands/grid.md | 2 +- docs/commands/into_binary.md | 2 +- docs/commands/into_bool.md | 4 +- docs/commands/into_int.md | 2 +- docs/commands/into_string.md | 2 +- docs/commands/let.md | 2 +- docs/commands/shells.md | 2 +- docs/commands/shuffle.md | 2 +- docs/make_docs.nu | 2 +- .../powershell/nu_plugin_mylen_filter.ps1 | 10 ++--- src/default_config.nu | 14 +++---- src/tests/test_conditionals.rs | 8 ++-- src/tests/test_custom_commands.rs | 2 +- src/tests/test_engine.rs | 20 ++++++--- src/tests/test_math.rs | 4 +- src/tests/test_parser.rs | 2 +- src/utils.rs | 42 +++++++++++++++---- tests/shell/pipeline/commands/internal.rs | 2 +- 50 files changed, 173 insertions(+), 100 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9c33a4d901..e2e7e068ba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,8 +73,8 @@ jobs: platform: [ubuntu-latest, macos-latest, windows-latest] rust: - stable - py: - - py + # py: + # - py runs-on: ${{ matrix.platform }} @@ -95,20 +95,20 @@ jobs: command: install args: --path=. --no-default-features - - name: Setup Python - uses: actions/setup-python@v2 - with: - python-version: "3.10" + # - name: Setup Python + # uses: actions/setup-python@v2 + # with: + # python-version: "3.10" - - run: python -m pip install tox + # - run: python -m pip install tox - - name: Install virtualenv - run: | - git clone https://github.com/kubouch/virtualenv.git && \ - cd virtualenv && \ - git checkout engine-q-update - shell: bash + # - name: Install virtualenv + # run: | + # git clone https://github.com/kubouch/virtualenv.git && \ + # cd virtualenv && \ + # git checkout engine-q-update + # shell: bash - - name: Test Nushell in virtualenv - run: cd virtualenv && tox -e ${{ matrix.py }} -- -k nushell - shell: bash + # - name: Test Nushell in virtualenv + # run: cd virtualenv && tox -e ${{ matrix.py }} -- -k nushell + # shell: bash diff --git a/crates/nu-cli/src/completions.rs b/crates/nu-cli/src/completions.rs index e952ddf272..b711e7a439 100644 --- a/crates/nu-cli/src/completions.rs +++ b/crates/nu-cli/src/completions.rs @@ -70,9 +70,7 @@ impl NuCompleter { ) -> Vec<(reedline::Span, String)> { let mut output = vec![]; - let builtins = [ - "$nu", "$scope", "$in", "$config", "$env", "$true", "$false", "$nothing", - ]; + let builtins = ["$nu", "$scope", "$in", "$config", "$env", "$nothing"]; for builtin in builtins { if builtin.as_bytes().starts_with(prefix) { diff --git a/crates/nu-command/src/conversions/into/binary.rs b/crates/nu-command/src/conversions/into/binary.rs index 6f3094fb77..570d765ace 100644 --- a/crates/nu-command/src/conversions/into/binary.rs +++ b/crates/nu-command/src/conversions/into/binary.rs @@ -61,7 +61,7 @@ impl Command for SubCommand { }, Example { description: "convert a boolean to a nushell binary primitive", - example: "$true | into binary", + example: "true | into binary", result: Some(Value::Binary { val: i64::from(1).to_le_bytes().to_vec(), span: Span::test_data(), diff --git a/crates/nu-command/src/conversions/into/bool.rs b/crates/nu-command/src/conversions/into/bool.rs index 88e14fee81..b5c4432643 100644 --- a/crates/nu-command/src/conversions/into/bool.rs +++ b/crates/nu-command/src/conversions/into/bool.rs @@ -42,7 +42,7 @@ impl Command for SubCommand { vec![ Example { description: "Convert value to boolean in table", - example: "echo [[value]; ['false'] ['1'] [0] [1.0] [$true]] | into bool value", + example: "echo [[value]; ['false'] ['1'] [0] [1.0] [true]] | into bool value", result: Some(Value::List { vals: vec![ Value::Record { @@ -76,7 +76,7 @@ impl Command for SubCommand { }, Example { description: "Convert bool to boolean", - example: "$true | into bool", + example: "true | into bool", result: Some(Value::boolean(true, span)), }, Example { diff --git a/crates/nu-command/src/conversions/into/int.rs b/crates/nu-command/src/conversions/into/int.rs index 497f606828..d8c211f189 100644 --- a/crates/nu-command/src/conversions/into/int.rs +++ b/crates/nu-command/src/conversions/into/int.rs @@ -75,7 +75,7 @@ impl Command for SubCommand { }, Example { description: "Convert bool to integer", - example: "[$false, $true] | into int", + example: "[false, true] | into int", result: Some(Value::List { vals: vec![Value::test_int(0), Value::test_int(1)], span: Span::test_data(), diff --git a/crates/nu-command/src/conversions/into/string.rs b/crates/nu-command/src/conversions/into/string.rs index 76863fb3d1..f4eaa90a68 100644 --- a/crates/nu-command/src/conversions/into/string.rs +++ b/crates/nu-command/src/conversions/into/string.rs @@ -103,7 +103,7 @@ impl Command for SubCommand { }, Example { description: "convert boolean to string", - example: "$true | into string", + example: "true | into string", result: Some(Value::String { val: "true".to_string(), span: Span::test_data(), diff --git a/crates/nu-command/src/core_commands/debug.rs b/crates/nu-command/src/core_commands/debug.rs index e0cc0c952e..67062924c8 100644 --- a/crates/nu-command/src/core_commands/debug.rs +++ b/crates/nu-command/src/core_commands/debug.rs @@ -60,8 +60,7 @@ impl Command for Debug { }, Example { description: "Print the value of a table", - example: - "echo [[version patch]; [0.1.0 $false] [0.1.1 $true] [0.2.0 $false]] | debug", + example: "echo [[version patch]; [0.1.0 false] [0.1.1 true] [0.2.0 false]] | debug", result: Some(Value::List { vals: vec![ Value::test_string("{version: 0.1.0, patch: false}"), diff --git a/crates/nu-command/src/core_commands/let_.rs b/crates/nu-command/src/core_commands/let_.rs index f25cc8788c..69a560ca6c 100644 --- a/crates/nu-command/src/core_commands/let_.rs +++ b/crates/nu-command/src/core_commands/let_.rs @@ -70,7 +70,7 @@ impl Command for Let { }, Example { description: "Set a variable based on the condition", - example: "let x = if $false { -1 } else { 1 }", + example: "let x = if false { -1 } else { 1 }", result: None, }, ] diff --git a/crates/nu-command/src/core_commands/tutor.rs b/crates/nu-command/src/core_commands/tutor.rs index 810e2c0f0e..1da23fa411 100644 --- a/crates/nu-command/src/core_commands/tutor.rs +++ b/crates/nu-command/src/core_commands/tutor.rs @@ -351,7 +351,7 @@ ls | each {|x| $x.name} ``` The above will create a list of the filenames in the directory. ``` -if $true { echo "it's true" } { echo "it's not true" } +if true { echo "it's true" } { echo "it's not true" } ``` This `if` call will run the first block if the expression is true, or the second block if the expression is false. diff --git a/crates/nu-command/src/dataframe/eager/filter_with.rs b/crates/nu-command/src/dataframe/eager/filter_with.rs index cdaf1cb456..5e6aff47a7 100644 --- a/crates/nu-command/src/dataframe/eager/filter_with.rs +++ b/crates/nu-command/src/dataframe/eager/filter_with.rs @@ -28,7 +28,7 @@ impl Command for FilterWith { fn examples(&self) -> Vec { vec![Example { description: "Filter dataframe using a bool mask", - example: r#"let mask = ([$true $false] | dfr to-df); + example: r#"let mask = ([true false] | dfr to-df); [[a b]; [1 2] [3 4]] | dfr to-df | dfr filter-with $mask"#, result: Some( NuDataFrame::try_from_columns(vec![ diff --git a/crates/nu-command/src/dataframe/eager/to_df.rs b/crates/nu-command/src/dataframe/eager/to_df.rs index 4feee1856d..c2558009e2 100644 --- a/crates/nu-command/src/dataframe/eager/to_df.rs +++ b/crates/nu-command/src/dataframe/eager/to_df.rs @@ -86,7 +86,7 @@ impl Command for ToDataFrame { }, Example { description: "Takes a list of booleans and creates a dataframe", - example: "[$true $true $false] | dfr to-df", + example: "[true true false] | dfr to-df", result: Some( NuDataFrame::try_from_columns(vec![Column::new( "0".to_string(), diff --git a/crates/nu-command/src/dataframe/series/all_false.rs b/crates/nu-command/src/dataframe/series/all_false.rs index 99955e319a..20d282fe1d 100644 --- a/crates/nu-command/src/dataframe/series/all_false.rs +++ b/crates/nu-command/src/dataframe/series/all_false.rs @@ -26,7 +26,7 @@ impl Command for AllFalse { vec![ Example { description: "Returns true if all values are false", - example: "[$false $false $false] | dfr to-df | dfr all-false", + example: "[false false false] | dfr to-df | dfr all-false", result: Some( NuDataFrame::try_from_columns(vec![Column::new( "all_false".to_string(), diff --git a/crates/nu-command/src/dataframe/series/all_true.rs b/crates/nu-command/src/dataframe/series/all_true.rs index 693b8cb98c..3116faf1d7 100644 --- a/crates/nu-command/src/dataframe/series/all_true.rs +++ b/crates/nu-command/src/dataframe/series/all_true.rs @@ -26,7 +26,7 @@ impl Command for AllTrue { vec![ Example { description: "Returns true if all values are true", - example: "[$true $true $true] | dfr to-df | dfr all-true", + example: "[true true true] | dfr to-df | dfr all-true", result: Some( NuDataFrame::try_from_columns(vec![Column::new( "all_true".to_string(), diff --git a/crates/nu-command/src/dataframe/series/indexes/arg_true.rs b/crates/nu-command/src/dataframe/series/indexes/arg_true.rs index 12af3ed086..7002aefa10 100644 --- a/crates/nu-command/src/dataframe/series/indexes/arg_true.rs +++ b/crates/nu-command/src/dataframe/series/indexes/arg_true.rs @@ -26,7 +26,7 @@ impl Command for ArgTrue { fn examples(&self) -> Vec { vec![Example { description: "Returns indexes where values are true", - example: "[$false $true $false] | dfr to-df | dfr arg-true", + example: "[false true false] | dfr to-df | dfr arg-true", result: Some( NuDataFrame::try_from_columns(vec![Column::new( "arg_true".to_string(), diff --git a/crates/nu-command/src/dataframe/series/masks/not.rs b/crates/nu-command/src/dataframe/series/masks/not.rs index 636ee2818f..f7671f82e7 100644 --- a/crates/nu-command/src/dataframe/series/masks/not.rs +++ b/crates/nu-command/src/dataframe/series/masks/not.rs @@ -28,7 +28,7 @@ impl Command for NotSeries { fn examples(&self) -> Vec { vec![Example { description: "Inverts boolean mask", - example: "[$true $false $true] | dfr to-df | dfr not", + example: "[true false true] | dfr to-df | dfr not", result: Some( NuDataFrame::try_from_columns(vec![Column::new( "0".to_string(), diff --git a/crates/nu-command/src/filters/find.rs b/crates/nu-command/src/filters/find.rs index 6fb40879d0..f1c473d437 100644 --- a/crates/nu-command/src/filters/find.rs +++ b/crates/nu-command/src/filters/find.rs @@ -91,7 +91,7 @@ impl Command for Find { }, Example { description: "Find if a service is not running", - example: "[[version patch]; [0.1.0 $false] [0.1.1 $true] [0.2.0 $false]] | find -p { |it| $it.patch }", + example: "[[version patch]; [0.1.0 false] [0.1.1 true] [0.2.0 false]] | find -p { |it| $it.patch }", result: Some(Value::List { vals: vec![Value::test_record( vec!["version", "patch"], diff --git a/crates/nu-command/src/filters/shuffle.rs b/crates/nu-command/src/filters/shuffle.rs index 0f121d0cd4..9832500c75 100644 --- a/crates/nu-command/src/filters/shuffle.rs +++ b/crates/nu-command/src/filters/shuffle.rs @@ -38,7 +38,7 @@ impl Command for Shuffle { fn examples(&self) -> Vec { vec![Example { description: "Shuffle rows randomly (execute it several times and see the difference)", - example: r#"echo [[version patch]; [1.0.0 $false] [3.0.1 $true] [2.0.0 $false]] | shuffle"#, + example: r#"echo [[version patch]; [1.0.0 false] [3.0.1 true] [2.0.0 false]] | shuffle"#, result: None, }] } diff --git a/crates/nu-command/src/formats/to/nuon.rs b/crates/nu-command/src/formats/to/nuon.rs index d44e6adca3..65af8174e2 100644 --- a/crates/nu-command/src/formats/to/nuon.rs +++ b/crates/nu-command/src/formats/to/nuon.rs @@ -65,9 +65,9 @@ fn value_to_string(v: &Value, span: Span) -> Result { )), Value::Bool { val, .. } => { if *val { - Ok("$true".to_string()) + Ok("true".to_string()) } else { - Ok("$false".to_string()) + Ok("false".to_string()) } } Value::CellPath { .. } => Err(ShellError::UnsupportedInput( diff --git a/crates/nu-command/src/shells/shells_.rs b/crates/nu-command/src/shells/shells_.rs index 0123ba462e..c1fceded47 100644 --- a/crates/nu-command/src/shells/shells_.rs +++ b/crates/nu-command/src/shells/shells_.rs @@ -79,7 +79,7 @@ impl Command for Shells { }, Example { description: "Show currently active shell", - example: r#"shells | where active == $true"#, + example: r#"shells | where active == true"#, result: None, }, ] diff --git a/crates/nu-command/src/viewers/griddle.rs b/crates/nu-command/src/viewers/griddle.rs index 080379a989..b851dafe4e 100644 --- a/crates/nu-command/src/viewers/griddle.rs +++ b/crates/nu-command/src/viewers/griddle.rs @@ -169,7 +169,7 @@ prints out the list properly."# }, Example { description: "Render a table with 'name' column in it to a grid", - example: "[[name patch]; [0.1.0 $false] [0.1.1 $true] [0.2.0 $false]] | grid", + example: "[[name patch]; [0.1.0 false] [0.1.1 true] [0.2.0 false]] | grid", result: Some(Value::String { val: "0.1.0 │ 0.1.1 │ 0.2.0".to_string(), span: Span::test_data(), diff --git a/crates/nu-command/tests/commands/str_/into_string.rs b/crates/nu-command/tests/commands/str_/into_string.rs index 9a50bcd6ac..be0438bd53 100644 --- a/crates/nu-command/tests/commands/str_/into_string.rs +++ b/crates/nu-command/tests/commands/str_/into_string.rs @@ -45,7 +45,7 @@ fn from_boolean() { let actual = nu!( cwd: ".", pipeline( r#" - echo $true | into string + echo true | into string "# ) ); diff --git a/crates/nu-command/tests/format_conversions/nuon.rs b/crates/nu-command/tests/format_conversions/nuon.rs index b1a3d7ba9f..fb02c73a8d 100644 --- a/crates/nu-command/tests/format_conversions/nuon.rs +++ b/crates/nu-command/tests/format_conversions/nuon.rs @@ -65,7 +65,7 @@ fn to_nuon_bool() { let actual = nu!( cwd: "tests/fixtures/formats", pipeline( r#" - $false + false | to nuon | from nuon "# diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index a56f84c9de..e9849b4c14 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -49,6 +49,10 @@ pub fn is_math_expression_like(bytes: &[u8]) -> bool { return false; } + if bytes == b"true" || bytes == b"false" { + return true; + } + let b = bytes[0]; b == b'0' @@ -3258,6 +3262,41 @@ pub fn parse_value( return parse_variable_expr(working_set, span); } + if bytes == b"true" { + if matches!(shape, SyntaxShape::Boolean) || matches!(shape, SyntaxShape::Any) { + return ( + Expression { + expr: Expr::Bool(true), + span, + ty: Type::Bool, + custom_completion: None, + }, + None, + ); + } else { + return ( + Expression::garbage(span), + Some(ParseError::Expected("non-boolean value".into(), span)), + ); + } + } else if bytes == b"false" { + if matches!(shape, SyntaxShape::Boolean) || matches!(shape, SyntaxShape::Any) { + return ( + Expression { + expr: Expr::Bool(false), + span, + ty: Type::Bool, + custom_completion: None, + }, + None, + ); + } else { + return ( + Expression::garbage(span), + Some(ParseError::Expected("non-boolean value".into(), span)), + ); + } + } match bytes[0] { b'$' => return parse_dollar_expr(working_set, span), b'(' => { @@ -3381,7 +3420,7 @@ pub fn parse_value( } SyntaxShape::Boolean => { // Redundant, though we catch bad boolean parses here - if bytes == b"$true" || bytes == b"$false" { + if bytes == b"true" || bytes == b"false" { ( Expression { expr: Expr::Bool(true), @@ -3603,6 +3642,7 @@ pub fn parse_expression( while pos < spans.len() { // Check if there is any environment shorthand let name = working_set.get_span_contents(spans[pos]); + let split = name.split(|x| *x == b'='); let split: Vec<_> = split.collect(); if split.len() == 2 && !split[0].is_empty() { diff --git a/docs/How_To_Coloring_and_Theming.md b/docs/How_To_Coloring_and_Theming.md index 8f9127d67e..aa5c98b078 100644 --- a/docs/How_To_Coloring_and_Theming.md +++ b/docs/How_To_Coloring_and_Theming.md @@ -459,15 +459,15 @@ let base16_theme = { # now let's apply our regular config settings but also apply the "color_config:" theme that we specified above. let config = { - filesize_metric: $true + filesize_metric: true table_mode: rounded # basic, compact, compact_double, light, thin, with_love, rounded, reinforced, heavy, none, other - use_ls_colors: $true + use_ls_colors: true color_config: $base16_theme # <-- this is the theme - use_grid_icons: $true + use_grid_icons: true footer_mode: always #always, never, number_of_rows, auto - animate_prompt: $false + animate_prompt: false float_precision: 2 - without_color: $false + without_color: false filesize_format: "b" # b, kb, kib, mb, mib, gb, gib, tb, tib, pb, pib, eb, eib, zb, zib, auto edit_mode: emacs # vi max_history_size: 10000 diff --git a/docs/commands/debug.md b/docs/commands/debug.md index 5f4c2585ed..043f90bbb4 100644 --- a/docs/commands/debug.md +++ b/docs/commands/debug.md @@ -23,5 +23,5 @@ Print the value of a string Print the value of a table ```shell -> echo [[version patch]; [0.1.0 $false] [0.1.1 $true] [0.2.0 $false]] | debug +> echo [[version patch]; [0.1.0 false] [0.1.1 true] [0.2.0 false]] | debug ``` diff --git a/docs/commands/dfr_all-false.md b/docs/commands/dfr_all-false.md index 3530af79f5..b98291b1ca 100644 --- a/docs/commands/dfr_all-false.md +++ b/docs/commands/dfr_all-false.md @@ -14,7 +14,7 @@ Returns true if all values are false Returns true if all values are false ```shell -> [$false $false $false] | dfr to-df | dfr all-false +> [false false false] | dfr to-df | dfr all-false ``` Checks the result from a comparison diff --git a/docs/commands/dfr_all-true.md b/docs/commands/dfr_all-true.md index ee35eecdcc..a745087037 100644 --- a/docs/commands/dfr_all-true.md +++ b/docs/commands/dfr_all-true.md @@ -14,7 +14,7 @@ Returns true if all values are true Returns true if all values are true ```shell -> [$true $true $true] | dfr to-df | dfr all-true +> [true true true] | dfr to-df | dfr all-true ``` Checks the result from a comparison diff --git a/docs/commands/dfr_arg-true.md b/docs/commands/dfr_arg-true.md index 902b4a4fe4..7ee7a75e56 100644 --- a/docs/commands/dfr_arg-true.md +++ b/docs/commands/dfr_arg-true.md @@ -14,5 +14,5 @@ Returns indexes where values are true Returns indexes where values are true ```shell -> [$false $true $false] | dfr to-df | dfr arg-true +> [false true false] | dfr to-df | dfr arg-true ``` diff --git a/docs/commands/dfr_filter-with.md b/docs/commands/dfr_filter-with.md index ed588884d1..672833e40f 100644 --- a/docs/commands/dfr_filter-with.md +++ b/docs/commands/dfr_filter-with.md @@ -18,6 +18,6 @@ Filters dataframe using a mask as reference Filter dataframe using a bool mask ```shell -> let mask = ([$true $false] | dfr to-df); +> let mask = ([true false] | dfr to-df); [[a b]; [1 2] [3 4]] | dfr to-df | dfr filter-with $mask ``` diff --git a/docs/commands/dfr_not.md b/docs/commands/dfr_not.md index e244f4cfa7..71f5d26e73 100644 --- a/docs/commands/dfr_not.md +++ b/docs/commands/dfr_not.md @@ -14,5 +14,5 @@ Inverts boolean mask Inverts boolean mask ```shell -> [$true $false $true] | dfr to-df | dfr not +> [true false true] | dfr to-df | dfr not ``` diff --git a/docs/commands/dfr_to-df.md b/docs/commands/dfr_to-df.md index c4186fdbf5..ea8a12ca1b 100644 --- a/docs/commands/dfr_to-df.md +++ b/docs/commands/dfr_to-df.md @@ -29,5 +29,5 @@ Takes a list and creates a dataframe Takes a list of booleans and creates a dataframe ```shell -> [$true $true $false] | dfr to-df +> [true true false] | dfr to-df ``` diff --git a/docs/commands/find.md b/docs/commands/find.md index 02dbd26e0d..e72ba3d49c 100644 --- a/docs/commands/find.md +++ b/docs/commands/find.md @@ -49,7 +49,7 @@ Find odd values Find if a service is not running ```shell -> [[version patch]; [0.1.0 $false] [0.1.1 $true] [0.2.0 $false]] | find -p { |it| $it.patch } +> [[version patch]; [0.1.0 false] [0.1.1 true] [0.2.0 false]] | find -p { |it| $it.patch } ``` Find using regex diff --git a/docs/commands/grid.md b/docs/commands/grid.md index 0e96f2472c..8e29e0f8f7 100644 --- a/docs/commands/grid.md +++ b/docs/commands/grid.md @@ -40,5 +40,5 @@ Render a list of records to a grid Render a table with 'name' column in it to a grid ```shell -> [[name patch]; [0.1.0 $false] [0.1.1 $true] [0.2.0 $false]] | grid +> [[name patch]; [0.1.0 false] [0.1.1 true] [0.2.0 false]] | grid ``` diff --git a/docs/commands/into_binary.md b/docs/commands/into_binary.md index 3a547b1176..0db8995306 100644 --- a/docs/commands/into_binary.md +++ b/docs/commands/into_binary.md @@ -28,7 +28,7 @@ convert a number to a nushell binary primitive convert a boolean to a nushell binary primitive ```shell -> $true | into binary +> true | into binary ``` convert a filesize to a nushell binary primitive diff --git a/docs/commands/into_bool.md b/docs/commands/into_bool.md index 9767c30a1a..3268af5468 100644 --- a/docs/commands/into_bool.md +++ b/docs/commands/into_bool.md @@ -18,12 +18,12 @@ Convert value to boolean Convert value to boolean in table ```shell -> echo [[value]; ['false'] ['1'] [0] [1.0] [$true]] | into bool value +> echo [[value]; ['false'] ['1'] [0] [1.0] [true]] | into bool value ``` Convert bool to boolean ```shell -> $true | into bool +> true | into bool ``` convert integer to boolean diff --git a/docs/commands/into_int.md b/docs/commands/into_int.md index 7c36dfb47a..010f9ac4a4 100644 --- a/docs/commands/into_int.md +++ b/docs/commands/into_int.md @@ -44,7 +44,7 @@ Convert file size to integer Convert bool to integer ```shell -> [$false, $true] | into int +> [false, true] | into int ``` Convert to integer from binary diff --git a/docs/commands/into_string.md b/docs/commands/into_string.md index ad5914b950..4ced6686a3 100644 --- a/docs/commands/into_string.md +++ b/docs/commands/into_string.md @@ -49,7 +49,7 @@ convert string to string convert boolean to string ```shell -> $true | into string +> true | into string ``` convert date to string diff --git a/docs/commands/let.md b/docs/commands/let.md index 57b0309b60..c038420fae 100644 --- a/docs/commands/let.md +++ b/docs/commands/let.md @@ -29,5 +29,5 @@ Set a variable to the result of an expression Set a variable based on the condition ```shell -> let x = if $false { -1 } else { 1 } +> let x = if false { -1 } else { 1 } ``` diff --git a/docs/commands/shells.md b/docs/commands/shells.md index 2dde1cb22a..24d8aff7ef 100644 --- a/docs/commands/shells.md +++ b/docs/commands/shells.md @@ -19,5 +19,5 @@ Enter a new shell at parent path '..' and show all opened shells Show currently active shell ```shell -> shells | where active == $true +> shells | where active == true ``` diff --git a/docs/commands/shuffle.md b/docs/commands/shuffle.md index 3460fdcd28..c0dde3a9d5 100644 --- a/docs/commands/shuffle.md +++ b/docs/commands/shuffle.md @@ -14,5 +14,5 @@ Shuffle rows randomly. Shuffle rows randomly (execute it several times and see the difference) ```shell -> echo [[version patch]; [1.0.0 $false] [3.0.1 $true] [2.0.0 $false]] | shuffle +> echo [[version patch]; [1.0.0 false] [3.0.1 true] [2.0.0 false]] | shuffle ``` diff --git a/docs/make_docs.nu b/docs/make_docs.nu index a7316b284a..23d62d6869 100644 --- a/docs/make_docs.nu +++ b/docs/make_docs.nu @@ -1,6 +1,6 @@ let vers = (version).version -for command in ($scope.commands | where is_custom == $false && is_extern == $false) { +for command in ($scope.commands | where is_custom == false && is_extern == false) { let top = $"--- title: ($command.command) layout: command diff --git a/docs/sample_plugins/powershell/nu_plugin_mylen_filter.ps1 b/docs/sample_plugins/powershell/nu_plugin_mylen_filter.ps1 index c508d8ab15..964b7ab333 100644 --- a/docs/sample_plugins/powershell/nu_plugin_mylen_filter.ps1 +++ b/docs/sample_plugins/powershell/nu_plugin_mylen_filter.ps1 @@ -139,9 +139,9 @@ function end_filter { function Write-TraceMessage { Param ( - [Parameter(Mandatory = $false, Position = 0)] + [Parameter(Mandatory = false, Position = 0)] [string] $label, - [Parameter(Mandatory = $false, Position = 1)] + [Parameter(Mandatory = false, Position = 1)] [string] $message ) @@ -196,9 +196,9 @@ function Get-PipedData { param( [Parameter( Position = 0, - Mandatory = $true, - ValueFromPipeline = $true, - ValueFromPipelineByPropertyName = $true) + Mandatory = true, + ValueFromPipeline = true, + ValueFromPipelineByPropertyName = true) ] [Alias('piped')] [String]$piped_input diff --git a/src/default_config.nu b/src/default_config.nu index c6ab47efbe..7435105c98 100644 --- a/src/default_config.nu +++ b/src/default_config.nu @@ -162,17 +162,17 @@ let default_theme = { # The default config record. This is where much of your global configuration is setup. let $config = { - filesize_metric: $false + filesize_metric: false table_mode: rounded # basic, compact, compact_double, light, thin, with_love, rounded, reinforced, heavy, none, other - use_ls_colors: $true - rm_always_trash: $false + use_ls_colors: true + rm_always_trash: false color_config: $default_theme - use_grid_icons: $true + use_grid_icons: true footer_mode: "25" # always, never, number_of_rows, auto - quick_completions: $true # set this to $false to prevent auto-selecting completions when only one remains - animate_prompt: $false # redraw the prompt every second + quick_completions: true # set this to false to prevent auto-selecting completions when only one remains + animate_prompt: false # redraw the prompt every second float_precision: 2 - use_ansi_coloring: $true + use_ansi_coloring: true filesize_format: "auto" # b, kb, kib, mb, mib, gb, gib, tb, tib, pb, pib, eb, eib, zb, zib, auto edit_mode: emacs # emacs, vi max_history_size: 10000 diff --git a/src/tests/test_conditionals.rs b/src/tests/test_conditionals.rs index f826c23a79..285485c92e 100644 --- a/src/tests/test_conditionals.rs +++ b/src/tests/test_conditionals.rs @@ -2,22 +2,22 @@ use crate::tests::{run_test, TestResult}; #[test] fn if_test1() -> TestResult { - run_test("if $true { 10 } else { 20 } ", "10") + run_test("if true { 10 } else { 20 } ", "10") } #[test] fn if_test2() -> TestResult { - run_test("if $false { 10 } else { 20 } ", "20") + run_test("if false { 10 } else { 20 } ", "20") } #[test] fn simple_if() -> TestResult { - run_test("if $true { 10 } ", "10") + run_test("if true { 10 } ", "10") } #[test] fn simple_if2() -> TestResult { - run_test("if $false { 10 } ", "") + run_test("if false { 10 } ", "") } #[test] diff --git a/src/tests/test_custom_commands.rs b/src/tests/test_custom_commands.rs index 1d4ff39f95..45a2acaee9 100644 --- a/src/tests/test_custom_commands.rs +++ b/src/tests/test_custom_commands.rs @@ -3,7 +3,7 @@ use crate::tests::{fail_test, run_test, TestResult}; #[test] fn no_scope_leak1() -> TestResult { fail_test( - "if $false { let $x = 10 } else { let $x = 20 }; $x", + "if false { let $x = 10 } else { let $x = 20 }; $x", "Variable not found", ) } diff --git a/src/tests/test_engine.rs b/src/tests/test_engine.rs index cfaff509a4..5ad9ab4c7e 100644 --- a/src/tests/test_engine.rs +++ b/src/tests/test_engine.rs @@ -17,7 +17,7 @@ fn proper_shadow() -> TestResult { fn config_filesize_format_with_metric_true() -> TestResult { // Note: this tests both the config variable and that it is properly captured into a block run_test( - r#"let config = {"filesize_metric": $true "filesize_format": "kib" }; do { 40kb | into string } "#, + r#"let config = {"filesize_metric": true "filesize_format": "kib" }; do { 40kb | into string } "#, "39.1 KiB", ) } @@ -26,7 +26,7 @@ fn config_filesize_format_with_metric_true() -> TestResult { fn config_filesize_format_with_metric_false_kib() -> TestResult { // Note: this tests both the config variable and that it is properly captured into a block run_test( - r#"let config = {"filesize_metric": $false "filesize_format": "kib" }; do { 40kb | into string } "#, + r#"let config = {"filesize_metric": false "filesize_format": "kib" }; do { 40kb | into string } "#, "39.1 KiB", ) } @@ -35,7 +35,7 @@ fn config_filesize_format_with_metric_false_kib() -> TestResult { fn config_filesize_format_with_metric_false_kb() -> TestResult { // Note: this tests both the config variable and that it is properly captured into a block run_test( - r#"let config = {"filesize_metric": $false "filesize_format": "kb" }; do { 40kb | into string } "#, + r#"let config = {"filesize_metric": false "filesize_format": "kb" }; do { 40kb | into string } "#, "40.0 KB", ) } @@ -265,15 +265,25 @@ fn datetime_literal() -> TestResult { #[test] fn shortcircuiting_and() -> TestResult { - run_test(r#"$false && (5 / 0; $false)"#, "false") + run_test(r#"false && (5 / 0; false)"#, "false") } #[test] fn shortcircuiting_or() -> TestResult { - run_test(r#"$true || (5 / 0; $false)"#, "true") + run_test(r#"true || (5 / 0; false)"#, "true") } #[test] fn open_ended_range() -> TestResult { run_test(r#"1.. | first 100000 | length"#, "100000") } + +#[test] +fn bool_variable() -> TestResult { + run_test(r#"$true"#, "true") +} + +#[test] +fn bool_variable2() -> TestResult { + run_test(r#"$false"#, "false") +} diff --git a/src/tests/test_math.rs b/src/tests/test_math.rs index 5a1e462f18..b4d4878f0f 100644 --- a/src/tests/test_math.rs +++ b/src/tests/test_math.rs @@ -27,12 +27,12 @@ fn modulo2() -> TestResult { #[test] fn and() -> TestResult { - run_test("$true && $false", "false") + run_test("true && false", "false") } #[test] fn or() -> TestResult { - run_test("$true || $false", "true") + run_test("true || false", "true") } #[test] diff --git a/src/tests/test_parser.rs b/src/tests/test_parser.rs index a4466d9e5f..ec04eeaba8 100644 --- a/src/tests/test_parser.rs +++ b/src/tests/test_parser.rs @@ -4,7 +4,7 @@ use super::run_test_contains; #[test] fn env_shorthand() -> TestResult { - run_test("FOO=BAR if $false { 3 } else { 4 }", "4") + run_test("FOO=BAR if false { 3 } else { 4 }", "4") } #[test] diff --git a/src/utils.rs b/src/utils.rs index af4c4fa0db..1cf088bd0c 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -284,6 +284,32 @@ pub(crate) fn eval_source( true } +fn seems_like_number(bytes: &[u8]) -> bool { + if bytes.is_empty() { + false + } else { + let b = bytes[0]; + + b == b'0' + || b == b'1' + || b == b'2' + || b == b'3' + || b == b'4' + || b == b'5' + || b == b'6' + || b == b'7' + || b == b'8' + || b == b'9' + || b == b'(' + || b == b'{' + || b == b'[' + || b == b'$' + || b == b'"' + || b == b'\'' + || b == b'-' + } +} + /// Finds externals that have names that look like math expressions pub fn external_exceptions(engine_state: &EngineState, stack: &Stack) -> Vec> { let mut executables = vec![]; @@ -299,16 +325,16 @@ pub fn external_exceptions(engine_state: &EngineState, stack: &Stack) -> Vec Vec