From 5e4cf85ce8926ef07bbb706e4eacd82b2acfccad Mon Sep 17 00:00:00 2001 From: Joshua Nussbaum <67082011+joshuanussbaum@users.noreply.github.com> Date: Sat, 21 Dec 2024 20:37:11 -0600 Subject: [PATCH 1/3] update zh-CN book --- zh-CN/book/3rdpartyprompts.md | 2 +- zh-CN/book/aliases.md | 6 +- zh-CN/book/coloring_and_theming.md | 12 +- zh-CN/book/configuration.md | 18 +- zh-CN/book/creating_errors.md | 17 +- zh-CN/book/custom_commands.md | 30 +- zh-CN/book/custom_completions.md | 8 +- zh-CN/book/dataframes.md | 10 +- zh-CN/book/environment.md | 64 ++-- zh-CN/book/escaping.md | 4 +- zh-CN/book/hooks.md | 12 +- zh-CN/book/introduction.md | 200 ++++++------ zh-CN/book/loading_data.md | 128 ++++---- zh-CN/book/metadata.md | 34 +- zh-CN/book/modules.md | 120 ++++---- zh-CN/book/operators.md | 4 +- zh-CN/book/overlays.md | 22 +- zh-CN/book/parallelism.md | 6 +- zh-CN/book/pipelines.md | 10 +- zh-CN/book/plugins.md | 6 +- zh-CN/book/scripts.md | 12 +- zh-CN/book/stdout_stderr_exit_codes.md | 24 +- zh-CN/book/thinking_in_nu.md | 58 ++-- zh-CN/book/types_of_data.md | 112 +++---- zh-CN/book/variables_and_subexpressions.md | 48 +-- zh-CN/book/working_with_lists.md | 8 +- zh-CN/book/working_with_strings.md | 94 +++--- zh-CN/book/working_with_tables.md | 342 ++++++++++----------- 28 files changed, 705 insertions(+), 706 deletions(-) diff --git a/zh-CN/book/3rdpartyprompts.md b/zh-CN/book/3rdpartyprompts.md index fa3cced03b4..31f975afd46 100644 --- a/zh-CN/book/3rdpartyprompts.md +++ b/zh-CN/book/3rdpartyprompts.md @@ -21,7 +21,7 @@ Nerdfonts 并不是必需的,但它们能使呈现效果更好。 3. 在`~/.config/nushell/config.nu`(或由`$nu.config-path`输出的路径)中设置`PROMPT_COMMAND`,将`M365Princess.mp.json`改为你喜欢的任何 [主题](https://ohmyposh.dev/docs/themes)。 ```nu -> $env.PROMPT_COMMAND = { oh-my-posh --config ~/.poshthemes/M365Princess.omp.json } +$env.PROMPT_COMMAND = { oh-my-posh --config ~/.poshthemes/M365Princess.omp.json } ``` MacOS 用户配置步骤: diff --git a/zh-CN/book/aliases.md b/zh-CN/book/aliases.md index ba1833e60e2..b167037f15b 100644 --- a/zh-CN/book/aliases.md +++ b/zh-CN/book/aliases.md @@ -5,19 +5,19 @@ Nushell 中的别名提供了一种简单的文本替换方式,这允许你为 例如,让我们创建一个名为 `ll` 的别名,它将展开为 `ls -l`。 ```nu -> alias ll = ls -l +alias ll = ls -l ``` 我们可以通过别名来调用它: ```nu -> ll +ll ``` 一旦我们这样做了,就如同我们输入了 `ls -l` 一样。这也允许我们传入标志或位置参数。例如,我们现在也可以这样写: ``` -> ll -a +ll -a ``` 可得到与输入了`ls -l -a`一样的结果。 diff --git a/zh-CN/book/coloring_and_theming.md b/zh-CN/book/coloring_and_theming.md index cb54e2d4482..8c31161fea8 100644 --- a/zh-CN/book/coloring_and_theming.md +++ b/zh-CN/book/coloring_and_theming.md @@ -15,7 +15,7 @@ Nushell 界面的许多部分都可以定制它们的颜色,所有这些都可 表的边框由`config.nu`中的`table_mode`设置来控制。下面是一个例子: ```nu -> $env.config = { +$env.config = { table_mode: rounded } ``` @@ -269,7 +269,7 @@ Nushell 界面的许多部分都可以定制它们的颜色,所有这些都可 下面是一个改变其中一些数值的小例子。 ```nu -> let config = { +let config = { color_config: { separator: purple leading_trailing_space_bg: "#ffffff" @@ -294,7 +294,7 @@ Nushell 界面的许多部分都可以定制它们的颜色,所有这些都可 下面是另一个使用多种颜色语法的小例子,其中有一些注释: ```nu -> let config = { +let config = { color_config: { separator: "#88b719" # this sets only the foreground color like PR #486 leading_trailing_space_bg: white # this sets only the foreground color in the original style @@ -348,7 +348,7 @@ Nushell 界面的许多部分都可以定制它们的颜色,所有这些都可 这里有一个小例子,说明如何对这些项目应用颜色。任何没有显示指定的都会被设置为默认的颜色。 ```nu -> $env.config = { +$env.config = { color_config: { shape_garbage: { fg: "#FFFFFF" bg: "#FF0000" attr: b} shape_bool: green @@ -371,13 +371,13 @@ Nushell 的提示符可以通过这些环境变量进行配置: 例如:对于一个简单的提示,我们可以这样做。注意`PROMPT_COMMAND`需要一个`block`而其他的需要一个`string`。 ```nu -> $env.PROMPT_COMMAND = { build-string (date now | format date '%m/%d/%Y %I:%M:%S%.3f') ': ' (pwd | path basename) } +$env.PROMPT_COMMAND = { build-string (date now | format date '%m/%d/%Y %I:%M:%S%.3f') ': ' (pwd | path basename) } ``` 如果你不喜欢默认的`PROMPT_INDICATOR`,你可以这样改变它: ```nu -> $env.PROMPT_INDICATOR = "> " +$env.PROMPT_INDICATOR = "> " ``` 提示的颜色由 `PROMPT_COMMAND` 中的 `block` 控制,在这里你可以编写自己的自定义提示。我们写了一个稍微花哨点的,有 git 状态的,位于 [nu_scripts 仓库](https://github.com/nushell/nu_scripts/blob/main/prompt/oh-my.nu)。 diff --git a/zh-CN/book/configuration.md b/zh-CN/book/configuration.md index ec4fef25d92..d5313466c33 100644 --- a/zh-CN/book/configuration.md +++ b/zh-CN/book/configuration.md @@ -81,15 +81,15 @@ $env | reject config | transpose key val | each {|r| echo $"$env.($r.key) = '($r 接下来,在一些发行版上,你还需要确保 Nu 在`/etc/shells`列表中: ```nu -> cat /etc/shells -# /etc/shells: valid login shells -/bin/sh -/bin/dash -/bin/bash -/bin/rbash -/usr/bin/screen -/usr/bin/fish -/home/sophia/.cargo/bin/nu +cat /etc/shells +# => # /etc/shells: valid login shells +# => /bin/sh +# => /bin/dash +# => /bin/bash +# => /bin/rbash +# => /usr/bin/screen +# => /usr/bin/fish +# => /home/sophia/.cargo/bin/nu ``` 这样你就可以使用`chsh`命令来将 Nu 设置为你的登录 Shell。在你注销后下次登录时,应该可以看到一个闪亮的 Nu 提示。 diff --git a/zh-CN/book/creating_errors.md b/zh-CN/book/creating_errors.md index 75973d99ca7..1843da5660a 100644 --- a/zh-CN/book/creating_errors.md +++ b/zh-CN/book/creating_errors.md @@ -38,13 +38,12 @@ def my-command [x] { 现在当传入一个值调用时,我们会看到一个错误信息返回: ```nu -> my-command 100 - -Error: - × this is fishy - ╭─[entry #5:1:1] - 1 │ my-command 100 - · ─┬─ - · ╰── fish right here - ╰──── +my-command 100 +# => Error: +# => × this is fishy +# => ╭─[entry #5:1:1] +# => 1 │ my-command 100 +# => · ─┬─ +# => · ╰── fish right here +# => ╰──── ``` diff --git a/zh-CN/book/custom_commands.md b/zh-CN/book/custom_commands.md index c69177f0d40..c3d5c2737f5 100644 --- a/zh-CN/book/custom_commands.md +++ b/zh-CN/book/custom_commands.md @@ -17,7 +17,7 @@ def greet [name] { 要运行上述命令,我们可以像调用内置命令一样调用它: ```nu -> greet "world" +greet "world" ``` 当我们这样做的时候,就会得到输出,如同我们使用内置命令一样: @@ -62,7 +62,7 @@ def "str mycommand" [] { 现在我们可以像调用`str`的内置子命令一样调用我们的自定义命令: ```nu -> str mycommand +str mycommand ``` ## 参数类型 @@ -137,10 +137,10 @@ def greet [name = "nushell"] { 你可以在没有参数的情况下调用这个命令,也可以指定一个值来覆盖默认值: ``` -> greet -hello nushell -> greet world -hello world +greet +# => hello nushell +greet world +# => hello world ``` 你也可以将默认值与[类型要求](#参数类型)相结合: @@ -217,19 +217,19 @@ def greet [ 你可以用以下方法调用上述内容: ```nu -> greet world --age 10 +greet world --age 10 ``` 或者: ```nu -> greet --age 10 world +greet --age 10 world ``` 或者甚至完全不使用标志: ``` -> greet world +greet world ``` 标志也可以指定一个缩写版本,这允许你传递一个更简单的标志,如同传递一个更容易阅读的全写标志那样。 @@ -250,7 +250,7 @@ _注意:_ 标志是以其全称命名的,所以上面的例子的命令体 现在,我们可以使用缩写标志来调用这个新的定义: ``` -> greet -a 10 hello +greet -a 10 hello ``` 标志也可以作为基本开关使用,这意味着它们的存在或不存在被当作定义的参数。延伸前面的例子: @@ -272,13 +272,13 @@ def greet [ 而这个定义可以通过如下方式调用: ``` -> greet -a 10 --twice hello +greet -a 10 --twice hello ``` 或者只是没有开关标志: ``` -> greet -a 10 hello +greet -a 10 hello ``` ## 剩余参数 @@ -380,7 +380,7 @@ Flags: 自定义命令会像内置命令一样流式输出。例如,假设我们想重构这个管道: ```nu -> ls | get name +ls | get name ``` 让我们把[`ls`](/commands/docs/ls.md)移到我们编写的命令中: @@ -392,7 +392,7 @@ def my-ls [] { ls } 我们就可以像使用[`ls`](/commands/docs/ls.md)一样使用这个命令的输出: ```nu -> my-ls | get name +my-ls | get name ───┬─────────────────────── 0 │ myscript.nu 1 │ myscript2.nu @@ -417,7 +417,7 @@ def double [] { 现在,如果我们在一个管道中调用上述命令,就可以看到它对输入的处理结果: ``` -> [1 2 3] | double +[1 2 3] | double ───┬───── 0 │ 2 1 │ 4 diff --git a/zh-CN/book/custom_completions.md b/zh-CN/book/custom_completions.md index 370a2012a10..7de4a1c670d 100644 --- a/zh-CN/book/custom_completions.md +++ b/zh-CN/book/custom_completions.md @@ -9,10 +9,10 @@ 我们来看一个例子: ```nu -> def animals [] { ["cat", "dog", "eel" ] } -> def my-command [animal: string@animals] { print $animal } ->| my-command -cat dog eel +def animals [] { ["cat", "dog", "eel" ] } +def my-command [animal: string@animals] { print $animal } +my-command +# => cat dog eel ``` 在第一行中,我们创建了一个自定义命令,将返回三个不同动物的列表。这些是我们想在补全中使用的值。一旦我们创建了这个命令,我们就可以用它来为其他自定义命令和 `extern` 提供补全。 diff --git a/zh-CN/book/dataframes.md b/zh-CN/book/dataframes.md index b38921b98ce..2531847ecec 100644 --- a/zh-CN/book/dataframes.md +++ b/zh-CN/book/dataframes.md @@ -14,10 +14,10 @@ 在这个小的性能测试练习中,我们将比较本地的 Nushell 原生命令、Nushell DataFrame 相关命令和[Python Pandas](https://pandas.pydata.org/)命令。暂时不要太在意`dataframe`命令,它们将在本页后面的章节中解释。 -> 系统细节:本节介绍的性能测试是用一台配备 Intel(R) Core(TM) i7-10710U -> (CPU @1.10GHz 1.61GHz)和 16 GB 内存的机器运行的。 -> -> 所有的例子都在 Nushell 0.78 版本上运行。 +系统细节:本节介绍的性能测试是用一台配备 Intel(R) Core(TM) i7-10710U +(CPU @1.10GHz 1.61GHz)和 16 GB 内存的机器运行的。 + +所有的例子都在 Nushell 0.78 版本上运行。 ### 文件信息 @@ -187,7 +187,7 @@ int_1,int_2,float_1,float_2,first,second,third,word 现在,要将该文件作为 DataFrame 进行读取,请使用 `dfr open` 命令,如下所示: ```nu -> let df = (dfr open test_small.csv) +let df = (dfr open test_small.csv) ``` 这应该会在内存中创建一个值 `$df`,用来存放我们刚刚创建的数据。 diff --git a/zh-CN/book/environment.md b/zh-CN/book/environment.md index 303d16f16e2..5883cf27a8a 100644 --- a/zh-CN/book/environment.md +++ b/zh-CN/book/environment.md @@ -30,7 +30,7 @@ Nushell 中使用的环境变量的实际值在`value`列下。 使用`$env.VAR = "val"`命令是最直接的方法: ```nu -> $env.FOO = 'BAR' +$env.FOO = 'BAR' ``` 因此,如果你想扩展`PATH`变量,你可以这样做: @@ -47,7 +47,7 @@ $env.PATH = ($env.PATH | prepend '/path/you/want/to/add') 如果你有一个以上的环境变量需要设置,你可以使用`load-env`并创建一个键/值对记录(Record),以用于加载多个环境变量: ```nu -> load-env { "BOB": "FOO", "JAY": "BAR" } +load-env { "BOB": "FOO", "JAY": "BAR" } ``` ### 一次性环境变量 @@ -68,8 +68,8 @@ $env.PATH = ($env.PATH | prepend '/path/you/want/to/add') 单个环境变量是记录的一个字段,存储在 `$env` 变量中,可以用 `$env.VARIABLE` 读取: ``` -> $env.FOO -BAR +$env.FOO +# => BAR ``` ## 作用域 @@ -79,14 +79,14 @@ BAR 这里有一个小例子来演示环境变量作用域: ```nu -> $env.FOO = "BAR" -> do { +$env.FOO = "BAR" +do { $env.FOO = "BAZ" $env.FOO == "BAZ" } -true -> $env.FOO == "BAR" -true +# => true +$env.FOO == "BAR" +# => true ``` ## 目录切换 @@ -100,15 +100,15 @@ Shell 中常见的任务是用[`cd`](/commands/docs/cd.md)命令来改变目录 在 Bash 和其他软件的启发下,有一个常用的简便方法,可以设置一次性环境变量: ```nu -> FOO=BAR echo $env.FOO -BAR +FOO=BAR echo $env.FOO +# => BAR ``` 你也可以使用[`with-env`](/commands/docs/with-env.md)来更明确地做同样的事情: ```nu -> with-env { FOO: BAR } { echo $env.FOO } -BAR +with-env { FOO: BAR } { echo $env.FOO } +# => BAR ``` [`with-env`](/commands/docs/with-env.md)命令将暂时把环境变量设置为给定的值(这里:变量 "FOO" 被赋为 "BAR" 值)。一旦这样做了,[块](types_of_data.html#块) 将在这个新的环境变量设置下运行。 @@ -130,14 +130,14 @@ $env.FOO = 'BAR' 然而,用[`def --env`](/commands/docs/def.md)而不是[`def`](/commands/docs/def.md)定义的命令(它也适用于`export def`,见 [模块](modules.md))将在调用者一方保留环境设置: ```nu -> def --env foo [] { +def --env foo [] { $env.FOO = 'BAR' } -> foo +foo -> $env.FOO -BAR +$env.FOO +# => BAR ``` ## 环境变量转换 @@ -164,26 +164,26 @@ $env.ENV_CONVERSIONS = { 现在,在一个 Nushell 实例内执行: ```nu -> with-env { FOO : 'a-b-c' } { nu } # runs Nushell with FOO env. var. set to 'a-b-c' +with-env { FOO : 'a-b-c' } { nu } # runs Nushell with FOO env. var. set to 'a-b-c' -> $env.FOO - 0 a - 1 b - 2 c +$env.FOO +# => 0 a +# => 1 b +# => 2 c ``` 你可以看到`$env.FOO`现在是一个新的 Nushell 实例中的列表,配置已经更新。 你也可以通过以下方式手动测试转换: ```nu -> do $env.ENV_CONVERSIONS.FOO.from_string 'a-b-c' +do $env.ENV_CONVERSIONS.FOO.from_string 'a-b-c' ``` 现在,为了测试列表->字符串的转换,运行: ```nu -> nu -c '$env.FOO' -a-b-c +nu -c '$env.FOO' +# => a-b-c ``` 因为`nu`是一个外部程序,Nushell 根据`ENV_CONVERSIONS.FOO.to_string`翻译了 `[ a b c ]` 列表,并把它传递给`nu`进程。 @@ -201,21 +201,21 @@ _(重要! 环境转换字符串->值发生在 `env.nu` 和 `config.nu` 被运行 只有当一个环境变量被设置在当前作用域中时,你才能通过 [`hide`](/commands/docs/hide.md) 命令“删除”它: ```nu -> $env.FOO = 'BAR' -... -> hide FOO +$env.FOO = 'BAR' +# => ... +hide FOO ``` 隐藏也是有作用域的,这既允许你暂时删除一个环境变量,又可以防止你从子作用域内修改父环境: ```nu -> $env.FOO = 'BAR' -> do { +$env.FOO = 'BAR' +do { hide FOO # $env.FOO does not exist } -> $env.FOO -BAR +$env.FOO +# => BAR ``` 关于隐藏的更多细节,请参考 [模块](modules.md#隐藏) diff --git a/zh-CN/book/escaping.md b/zh-CN/book/escaping.md index 6395343f12e..efbe1227f91 100644 --- a/zh-CN/book/escaping.md +++ b/zh-CN/book/escaping.md @@ -5,11 +5,11 @@ Nu 提供了一套你可以在不同操作系统中使用的命令(也成为" Nu 的内部命令: ```nu -> ls +ls ``` 转移到外部命令: ```nu -> ^ls +^ls ``` diff --git a/zh-CN/book/hooks.md b/zh-CN/book/hooks.md index 6768752ab83..a1c87e77b79 100644 --- a/zh-CN/book/hooks.md +++ b/zh-CN/book/hooks.md @@ -84,12 +84,12 @@ $env.config = ($env.config | upsert hooks { 你可以用下面的例子测试一下: ```nu -> $env.config = ($env.config | upsert hooks { +$env.config = ($env.config | upsert hooks { pre_prompt: { $env.SPAM = "eggs" } }) -> $env.SPAM -eggs +$env.SPAM +# => eggs ``` 钩子代码块遵循一般的作用域规则,即在块内定义的命令、别名等将在代码块结束后被丢掉。 @@ -146,12 +146,12 @@ $env.config = ($env.config | upsert hooks { 所以,上一节中的钩子也可以写成: ```nu -> $env.config = ($env.config | upsert hooks { +$env.config = ($env.config | upsert hooks { pre_prompt: '$env.SPAM = "eggs"' }) -> $env.SPAM -eggs +$env.SPAM +# => eggs ``` 这个功能可以用来,例如,根据当前目录有条件地引入定义: diff --git a/zh-CN/book/introduction.md b/zh-CN/book/introduction.md index f4d63a166a1..9ae19960a1c 100644 --- a/zh-CN/book/introduction.md +++ b/zh-CN/book/introduction.md @@ -13,17 +13,17 @@ Nu 从许多熟悉的领域中汲取了线索:bash 等传统 shell,PowerShel 当你运行一个类似 `ls` 的命令时,第一个注意到的是所得到的不是一个文本块,而是一个结构化的表。 ``` -> ls -────┬────────────────────┬──────┬────────┬──────────── - # │ name │ type │ size │ modified -────┼────────────────────┼──────┼────────┼──────────── - 0 │ 404.html │ File │ 429 B │ 3 days ago - 1 │ CONTRIBUTING.md │ File │ 955 B │ 8 mins ago - 2 │ Gemfile │ File │ 1.1 KB │ 3 days ago - 3 │ Gemfile.lock │ File │ 6.9 KB │ 3 days ago - 4 │ LICENSE │ File │ 1.1 KB │ 3 days ago - 5 │ README.md │ File │ 213 B │ 3 days ago -... +ls +# => ────┬────────────────────┬──────┬────────┬──────────── +# => # │ name │ type │ size │ modified +# => ────┼────────────────────┼──────┼────────┼──────────── +# => 0 │ 404.html │ File │ 429 B │ 3 days ago +# => 1 │ CONTRIBUTING.md │ File │ 955 B │ 8 mins ago +# => 2 │ Gemfile │ File │ 1.1 KB │ 3 days ago +# => 3 │ Gemfile.lock │ File │ 6.9 KB │ 3 days ago +# => 4 │ LICENSE │ File │ 1.1 KB │ 3 days ago +# => 5 │ README.md │ File │ 213 B │ 3 days ago +# => ... ``` 这个表不仅仅是用另一种方式显示了当前目录。就像电子表格中的表一样,我们可以更加交互性地处理数据。 @@ -31,17 +31,17 @@ Nu 从许多熟悉的领域中汲取了线索:bash 等传统 shell,PowerShel 我们做的第一件事是将表格通过尺寸来排序。为了做到这点,我们将会把 `ls` 的输出喂给一个可以根据列的内容来排序表格的命令。 ``` -> ls | sort-by size | reverse -────┬────────────────────┬──────┬────────┬──────────── - # │ name │ type │ size │ modified -────┼────────────────────┼──────┼────────┼──────────── - 0 │ Gemfile.lock │ File │ 6.9 KB │ 3 days ago - 1 │ SUMMARY.md │ File │ 3.7 KB │ 3 days ago - 2 │ Gemfile │ File │ 1.1 KB │ 3 days ago - 3 │ LICENSE │ File │ 1.1 KB │ 3 days ago - 4 │ CONTRIBUTING.md │ File │ 955 B │ 9 mins ago - 5 │ books.md │ File │ 687 B │ 3 days ago -... +ls | sort-by size | reverse +# => ────┬────────────────────┬──────┬────────┬──────────── +# => # │ name │ type │ size │ modified +# => ────┼────────────────────┼──────┼────────┼──────────── +# => 0 │ Gemfile.lock │ File │ 6.9 KB │ 3 days ago +# => 1 │ SUMMARY.md │ File │ 3.7 KB │ 3 days ago +# => 2 │ Gemfile │ File │ 1.1 KB │ 3 days ago +# => 3 │ LICENSE │ File │ 1.1 KB │ 3 days ago +# => 4 │ CONTRIBUTING.md │ File │ 955 B │ 9 mins ago +# => 5 │ books.md │ File │ 687 B │ 3 days ago +# => ... ``` 你可以看到我们没有给 `ls` 传递命令行参数。作为代替,我们使用了 Nu 提供的 `sort-by` 命令来排序 `ls` 的输出。为了让最大的文件位于顶部,我们还使用了 `reverse`。 @@ -49,28 +49,28 @@ Nu 从许多熟悉的领域中汲取了线索:bash 等传统 shell,PowerShel Nu 提供了许多可在表格上工作的命令。例如,我们可以过滤 `ls` 表格,只显示大于 1 KB 的文件: ``` -> ls | where size > 1kb -───┬──────────────┬──────┬────────┬──────────── - # │ name │ type │ size │ modified -───┼──────────────┼──────┼────────┼──────────── - 0 │ Gemfile │ File │ 1.1 KB │ 3 days ago - 1 │ Gemfile.lock │ File │ 6.9 KB │ 3 days ago - 2 │ LICENSE │ File │ 1.1 KB │ 3 days ago - 3 │ SUMMARY.md │ File │ 3.7 KB │ 3 days ago -───┴──────────────┴──────┴────────┴──────────── +ls | where size > 1kb +# => ───┬──────────────┬──────┬────────┬──────────── +# => # │ name │ type │ size │ modified +# => ───┼──────────────┼──────┼────────┼──────────── +# => 0 │ Gemfile │ File │ 1.1 KB │ 3 days ago +# => 1 │ Gemfile.lock │ File │ 6.9 KB │ 3 days ago +# => 2 │ LICENSE │ File │ 1.1 KB │ 3 days ago +# => 3 │ SUMMARY.md │ File │ 3.7 KB │ 3 days ago +# => ───┴──────────────┴──────┴────────┴──────────── ``` 就像 Unix 哲学所体现的那样,作为可以相互交流的命令,为我们提供了许多种不同的配对。让我们看一个不同的命令: ``` -> ps -─────┬───────┬──────────────────┬─────────┬─────────┬──────────┬───────── - # │ pid │ name │ status │ cpu │ mem │ virtual -─────┼───────┼──────────────────┼─────────┼─────────┼──────────┼───────── - 0 │ 33155 │ nu_plugin_core_p │ Running │ 3.8496 │ 1.8 MB │ 4.4 GB - 1 │ 32841 │ mdworker_shared │ Running │ 0.0000 │ 19.3 MB │ 4.4 GB - 2 │ 32829 │ CoreServicesUIAg │ Running │ 0.0000 │ 16.1 MB │ 4.5 GB - 3 │ 32828 │ mdworker_shared │ Running │ 0.0000 │ 23.0 MB │ 4.4 GB +ps +# => ─────┬───────┬──────────────────┬─────────┬─────────┬──────────┬───────── +# => # │ pid │ name │ status │ cpu │ mem │ virtual +# => ─────┼───────┼──────────────────┼─────────┼─────────┼──────────┼───────── +# => 0 │ 33155 │ nu_plugin_core_p │ Running │ 3.8496 │ 1.8 MB │ 4.4 GB +# => 1 │ 32841 │ mdworker_shared │ Running │ 0.0000 │ 19.3 MB │ 4.4 GB +# => 2 │ 32829 │ CoreServicesUIAg │ Running │ 0.0000 │ 16.1 MB │ 4.5 GB +# => 3 │ 32828 │ mdworker_shared │ Running │ 0.0000 │ 23.0 MB │ 4.4 GB ``` 如果你使用过 Linux,可能会对 `ps` 命令相当熟悉。这个命令为我们展示了系统所有正在运行的进程和它们的状态与名称。我们同样可以查看到它们的 CPU 占用。 @@ -78,13 +78,13 @@ Nu 提供了许多可在表格上工作的命令。例如,我们可以过滤 ` 如果我们想显示正在使用 CPU 的进程怎么办? 就像我们之前使用 `ls` 命令一样,我们也可以使用 `ps` 命令返回的表: ``` -> ps | where cpu > 10 -───┬──────┬──────────────────┬─────────┬────────┬──────────┬───────── - # │ pid │ name │ status │ cpu │ mem │ virtual -───┼──────┼──────────────────┼─────────┼────────┼──────────┼───────── - 0 │ 3971 │ Google Chrome He │ Running │ 5.1263 │ 99.4 MB │ 5.5 GB - 1 │ 360 │ iTerm2 │ Running │ 6.6635 │ 218.6 MB │ 6.0 GB -───┴──────┴──────────────────┴─────────┴────────┴──────────┴───────── +ps | where cpu > 10 +# => ───┬──────┬──────────────────┬─────────┬────────┬──────────┬───────── +# => # │ pid │ name │ status │ cpu │ mem │ virtual +# => ───┼──────┼──────────────────┼─────────┼────────┼──────────┼───────── +# => 0 │ 3971 │ Google Chrome He │ Running │ 5.1263 │ 99.4 MB │ 5.5 GB +# => 1 │ 360 │ iTerm2 │ Running │ 6.6635 │ 218.6 MB │ 6.0 GB +# => ───┴──────┴──────────────────┴─────────┴────────┴──────────┴───────── ``` 到目前为止,我们已经看到使用 `ls` 和 `ps` 列出文件和进程。 Nu 还提供了其他可以创建有用信息表的命令。 接下来,让我们探索`date` 和 `sys`。 @@ -92,56 +92,56 @@ Nu 提供了许多可在表格上工作的命令。例如,我们可以过滤 ` 运行 `date` 将给出当前日期与时间的信息: ``` -> date -──────────┬──────── - year │ 2020 - month │ 5 - day │ 5 - hour │ 21 - minute │ 13 - second │ 17 - timezone │ +02:00 -──────────┴──────── +date +# => ──────────┬──────── +# => year │ 2020 +# => month │ 5 +# => day │ 5 +# => hour │ 21 +# => minute │ 13 +# => second │ 17 +# => timezone │ +02:00 +# => ──────────┴──────── ``` 运行 `sys` 将给出 Nu 所运行的系统的信息: ``` -> sys -─────────┬───────────────────────────────────────── - host │ [row 7 columns] - cpu │ [row cores current ghz max ghz min ghz] - disks │ [table 2 rows] - mem │ [row free swap free swap total total] - net │ [table 11 rows] - battery │ [table 1 rows] -─────────┴───────────────────────────────────────── +sys +# => ─────────┬───────────────────────────────────────── +# => host │ [row 7 columns] +# => cpu │ [row cores current ghz max ghz min ghz] +# => disks │ [table 2 rows] +# => mem │ [row free swap free swap total total] +# => net │ [table 11 rows] +# => battery │ [table 1 rows] +# => ─────────┴───────────────────────────────────────── ``` 和之前的表有些不一样, `sys` 命令给出的表在单元格内包含了另一些结构化的表格,而非简单的数值。为了查看到这些数据,我们需要选择要看的列: ``` -> sys | get host -──────────┬───────────────────────────────────────────── - name │ Linux - release │ 5.3.0-1019-azure - version │ #20-Ubuntu SMP Fri Mar 27 23:54:23 UTC 2020 - hostname │ lifeless - arch │ x86_64 - uptime │ 8:03:47:32 - sessions │ [table 2 rows] -──────────┴───────────────────────────────────────────── +sys | get host +# => ──────────┬───────────────────────────────────────────── +# => name │ Linux +# => release │ 5.3.0-1019-azure +# => version │ #20-Ubuntu SMP Fri Mar 27 23:54:23 UTC 2020 +# => hostname │ lifeless +# => arch │ x86_64 +# => uptime │ 8:03:47:32 +# => sessions │ [table 2 rows] +# => ──────────┴───────────────────────────────────────────── ``` `get` 命令让我们跳入表格中一列的内容。这样,我们正在观看 "host" 列,它包含了关于 Nu 所运行的主机的信息。操作系统的名字、主机名、CPU 架构等等。让我们看看系统上的用户名: ``` -> sys | get host.sessions -───┬───────── - # │ -───┼───────── - 0 │ sophia -───┴───────── +sys | get host.sessions +# => ───┬───────── +# => # │ +# => ───┼───────── +# => 0 │ sophia +# => ───┴───────── ``` 目前,系统上只有一个用户,名为 `sophia`。 你会注意到,我们可以传递路径( `host.sessions` 部分),而不仅仅是传递列名。 Nu 将采用该路径并转到表中的相应数据位置。 @@ -151,8 +151,8 @@ Nu 提供了许多可在表格上工作的命令。例如,我们可以过滤 ` 让我们看看字符串如何在 Nu 之外起作用。 我们将从前面的示例开始,并运行外部的 `echo` 命令( `^` 告诉 nu 不要使用内置的 `echo` 命令): ``` -> sys | get host.sessions | ^echo $it -sophia +sys | get host.sessions | ^echo $it +# => sophia ``` 如果这看起来与我们以前的传统 Shell 非常相似,那么就说明你拥有敏锐的眼睛! 相似,但是有一个重要的区别:我们对前面看到的值调用了 `^echo` 。 这允许我们将数据从 Nu 传递到 `echo`(或 Nu 外部的任何命令,例如 `git`)。 @@ -160,21 +160,21 @@ sophia _注意:Nu 的内建命令的帮助文本可以用 `help` 来浏览_: ``` -> help config -Configuration management. - -Usage: - > config {flags} - -Subcommands: - config get - Gets a value from the config - config set - Sets a value in the config - config set_into - Sets a value in the config - config clear - clear the config - config load - Loads the config from the path given - config remove - Removes a value from the config - config path - return the path to the config file - -Flags: - -h, --help: Display this help message +help config +# => Configuration management. +# => +# => Usage: +# => > config {flags} +# => +# => Subcommands: +# => config get - Gets a value from the config +# => config set - Sets a value in the config +# => config set_into - Sets a value in the config +# => config clear - clear the config +# => config load - Loads the config from the path given +# => config remove - Removes a value from the config +# => config path - return the path to the config file +# => +# => Flags: +# => -h, --help: Display this help message ``` diff --git a/zh-CN/book/loading_data.md b/zh-CN/book/loading_data.md index b1e08eb237d..558d4284469 100644 --- a/zh-CN/book/loading_data.md +++ b/zh-CN/book/loading_data.md @@ -13,8 +13,8 @@ Nu 在处理数据方面最强大的能力之一是[`open`](/commands/docs/open. 如果我们想查看当前项目的版本,我们可以使用[`get`](/commands/docs/get.md)命令: ``` -> open editors/vscode/package.json | get version -1.0.0 +open editors/vscode/package.json | get version +# => 1.0.0 ``` Nu 目前支持直接从以下格式加载表数据: @@ -38,7 +38,7 @@ Nu 目前支持直接从以下格式加载表数据: 但是,当你加载其他的文本文件时会发生什么呢?让我们试一试: ```nu -> open README.md +open README.md ``` 我们会看到该文件的内容。 @@ -52,10 +52,10 @@ Nu 目前支持直接从以下格式加载表数据: 想象一下,我们得到了这个数据文件: ``` -> open people.txt -Octavia | Butler | Writer -Bob | Ross | Painter -Antonio | Vivaldi | Composer +open people.txt +# => Octavia | Butler | Writer +# => Bob | Ross | Painter +# => Antonio | Vivaldi | Composer ``` 我们想要的数据都由管道(`|`)符号隔开,每人单独一行。由于 Nu 没有默认的以管道分隔的文件格式,所以我们必须自己来解析。 @@ -63,75 +63,75 @@ Antonio | Vivaldi | Composer 当我们引入这个文件时,我们需要做的第一件事是确保后续每次只处理一行: ``` -> open people.txt | lines -───┬────────────────────────────── - 0 │ Octavia | Butler | Writer - 1 │ Bob | Ross | Painter - 2 │ Antonio | Vivaldi | Composer -───┴────────────────────────────── +open people.txt | lines +# => ───┬────────────────────────────── +# => 0 │ Octavia | Butler | Writer +# => 1 │ Bob | Ross | Painter +# => 2 │ Antonio | Vivaldi | Composer +# => ───┴────────────────────────────── ``` 可以看到,我们正在处理这些行,因为我们又回到了一个列表中。下一步是看看是否可以把行分割成更有用的东西。为此,我们将使用[`split`](/commands/docs/split.md)命令。[`split`](/commands/docs/split.md),顾名思义,为我们提供了一种分割字符串的方法。我们将使用[`split`](/commands/docs/split.md)的`column`子命令,将内容分成多列。我们会告诉它分隔符是什么,剩下的就由它来完成: ``` -> open people.txt | lines | split column "|" -───┬──────────┬───────────┬─────────── - # │ column1 │ column2 │ column3 -───┼──────────┼───────────┼─────────── - 0 │ Octavia │ Butler │ Writer - 1 │ Bob │ Ross │ Painter - 2 │ Antonio │ Vivaldi │ Composer -───┴──────────┴───────────┴─────────── +open people.txt | lines | split column "|" +# => ───┬──────────┬───────────┬─────────── +# => # │ column1 │ column2 │ column3 +# => ───┼──────────┼───────────┼─────────── +# => 0 │ Octavia │ Butler │ Writer +# => 1 │ Bob │ Ross │ Painter +# => 2 │ Antonio │ Vivaldi │ Composer +# => ───┴──────────┴───────────┴─────────── ``` 这看起来差不多了,只是还有一些额外的空白字符,让我们 [`trim`](/commands/docs/str_trim.md) 掉这些空格: ``` -> open people.txt | lines | split column "|" | str trim -───┬─────────┬─────────┬────────── - # │ column1 │ column2 │ column3 -───┼─────────┼─────────┼────────── - 0 │ Octavia │ Butler │ Writer - 1 │ Bob │ Ross │ Painter - 2 │ Antonio │ Vivaldi │ Composer -───┴─────────┴─────────┴────────── +open people.txt | lines | split column "|" | str trim +# => ───┬─────────┬─────────┬────────── +# => # │ column1 │ column2 │ column3 +# => ───┼─────────┼─────────┼────────── +# => 0 │ Octavia │ Butler │ Writer +# => 1 │ Bob │ Ross │ Painter +# => 2 │ Antonio │ Vivaldi │ Composer +# => ───┴─────────┴─────────┴────────── ``` 还不错,[`split`](/commands/docs/split.md)命令返回给我们可以使用的数据,还预设了默认的列名: ``` -> open people.txt | lines | split column "|" | str trim | get column1 -───┬───────── - 0 │ Octavia - 1 │ Bob - 2 │ Antonio -───┴───────── +open people.txt | lines | split column "|" | str trim | get column1 +# => ───┬───────── +# => 0 │ Octavia +# => 1 │ Bob +# => 2 │ Antonio +# => ───┴───────── ``` 我们也可以用自定义的列名代替默认的: ``` -> open people.txt | lines | split column "|" first_name last_name job | str trim -───┬────────────┬───────────┬────────── - # │ first_name │ last_name │ job -───┼────────────┼───────────┼────────── - 0 │ Octavia │ Butler │ Writer - 1 │ Bob │ Ross │ Painter - 2 │ Antonio │ Vivaldi │ Composer -───┴────────────┴───────────┴────────── +open people.txt | lines | split column "|" first_name last_name job | str trim +# => ───┬────────────┬───────────┬────────── +# => # │ first_name │ last_name │ job +# => ───┼────────────┼───────────┼────────── +# => 0 │ Octavia │ Butler │ Writer +# => 1 │ Bob │ Ross │ Painter +# => 2 │ Antonio │ Vivaldi │ Composer +# => ───┴────────────┴───────────┴────────── ``` 现在,我们的数据加载到一个表中了,我们可以使用之前对表所用的各种命令来处理它: ``` -> open people.txt | lines | split column "|" first_name last_name job | str trim | sort-by first_name -───┬────────────┬───────────┬────────── - # │ first_name │ last_name │ job -───┼────────────┼───────────┼────────── - 0 │ Antonio │ Vivaldi │ Composer - 1 │ Bob │ Ross │ Painter - 2 │ Octavia │ Butler │ Writer -───┴────────────┴───────────┴────────── +open people.txt | lines | split column "|" first_name last_name job | str trim | sort-by first_name +# => ───┬────────────┬───────────┬────────── +# => # │ first_name │ last_name │ job +# => ───┼────────────┼───────────┼────────── +# => 0 │ Antonio │ Vivaldi │ Composer +# => 1 │ Bob │ Ross │ Painter +# => 2 │ Octavia │ Butler │ Writer +# => ───┴────────────┴───────────┴────────── ``` 其他可用于字符串的命令有: @@ -143,12 +143,12 @@ Antonio | Vivaldi | Composer 如果我们已经知道待处理的数据具有 Nu 能够理解的格式,则可以使用一些辅助命令,例如,我们打开一个 Rust 的 Cargo.lock 文件: ```toml -> open Cargo.lock -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "adhoc_derive" -version = "0.1.2" +open Cargo.lock +# => # This file is automatically @generated by Cargo. +# => # It is not intended for manual editing. +# => [[package]] +# => name = "adhoc_derive" +# => version = "0.1.2" ``` "Cargo.lock" 实际上是一个 .toml 文件,但是文件扩展名不是 .toml。没关系,我们可以使用 `from toml` 命令: @@ -162,13 +162,13 @@ version = "0.1.2" 虽然能够打开一个文件并立即使用其数据表很有帮助,但这并不总是我们想要的。为了获得原始文本,[`open`](/commands/docs/open.md)命令可以接受一个可选的`--raw`标志: ```toml -> open Cargo.toml --raw -[package] -name = "nu" -version = "0.1.3" -authors = ["Yehuda Katz ", "Sophia Turner <547158+sophiajt@users.noreply.github.com>"] -description = "A shell for the GitHub era" -license = "MIT" +open Cargo.toml --raw +# => [package] +# => name = "nu" +# => version = "0.1.3" +# => authors = ["Yehuda Katz ", "Sophia Turner <547158+sophiajt@users.noreply.github.com>"] +# => description = "A shell for the GitHub era" +# => license = "MIT" ``` ## 获取 URLs diff --git a/zh-CN/book/metadata.md b/zh-CN/book/metadata.md index 7d5fa4a58d1..23b5f982bc9 100644 --- a/zh-CN/book/metadata.md +++ b/zh-CN/book/metadata.md @@ -3,14 +3,14 @@ 在使用 Nu 的过程中,你可能遇到过这样的情况:你觉得有一些额外的事情在幕后进行。例如,假设你试图打开一个 Nu 支持的文件,但却忘记了它已被 Nu 支持并试图再次转换: ``` -> open Cargo.toml | from toml -error: Expected a string from pipeline -- shell:1:18 -1 | open Cargo.toml | from toml - | ^^^^^^^^^ requires string input -- shell:1:5 -1 | open Cargo.toml | from toml - | ---------- object originates from here +open Cargo.toml | from toml +# => error: Expected a string from pipeline +# => - shell:1:18 +# => 1 | open Cargo.toml | from toml +# => | ^^^^^^^^^ requires string input +# => - shell:1:5 +# => 1 | open Cargo.toml | from toml +# => | ---------- object originates from here ``` 这个错误信息不仅告诉我们,我们给 `from toml` 的不是一个字符串,还告诉我们这个值最初来自哪里。那么它是如何知道的呢? @@ -20,20 +20,20 @@ error: Expected a string from pipeline 让我们再次运行[`open`](/commands/docs/open.md)命令,但这一次,我们将看一下它所反馈的标签: ``` -> metadata (open Cargo.toml) -╭──────┬───────────────────╮ -│ span │ {record 2 fields} │ -╰──────┴───────────────────╯ +metadata (open Cargo.toml) +# => ╭──────┬───────────────────╮ +# => │ span │ {record 2 fields} │ +# => ╰──────┴───────────────────╯ ``` 目前,我们只追踪值来自何处的起止范围(span)。让我们进一步仔细看看: ```nu -> metadata (open Cargo.toml) | get span -╭───────┬────────╮ -│ start │ 212970 │ -│ end │ 212987 │ -╰───────┴────────╯ +metadata (open Cargo.toml) | get span +# => ╭───────┬────────╮ +# => │ start │ 212970 │ +# => │ end │ 212987 │ +# => ╰───────┴────────╯ ``` 这里的范围 "start" 和 "end" 指的是下划线将标记在行中的位置。如果你数到 5,然后再数到 15,就会看到它与 "Cargo.toml" 文件名一致。这就是我们之前看到的错误是如何知道在何处标注下划线的。 diff --git a/zh-CN/book/modules.md b/zh-CN/book/modules.md index 36052b3c185..d34ced5280c 100644 --- a/zh-CN/book/modules.md +++ b/zh-CN/book/modules.md @@ -10,7 +10,7 @@ _注意! 目前对模块的实现是相当基本的,并将在未来进一步 一个简单的模块可以像这样定义: ```nu -> module greetings { +module greetings { export def hello [name: string] { $"hello ($name)!" } @@ -44,13 +44,13 @@ export def hi [where: string] { 模块本身并不做任何事情,要使用模块导出的定义,我们需要[`use`](/commands/docs/use.md)它: ```nu -> use greetings +use greetings -> greetings hello "world" -hello world! +# => greetings hello "world" +# => hello world! -> greetings hi "there" -hi there! +greetings hi "there" +# => hi there! ``` `hello`和`hi`命令现在可以通过`greetings`前缀被调用。 @@ -96,13 +96,13 @@ export def hi [where: string] { 现在,你可以直接在文件上调用[`use`](/commands/docs/use.md): ```nu -> use greetings.nu +use greetings.nu -> greetings hello "world" -hello world! +# => greetings hello "world" +# => hello world! -> greetings hi "there" -hi there! +greetings hi "there" +# => hi there! ``` Nushell 会自动从文件名("greetings",没有".nu"扩展名)推断出模块的名称。所以你可以通过文件名而不是模块名配合使用上述任何导入模式来完成导入。 @@ -130,15 +130,15 @@ def greetings-helper [greeting: string, subject: string] { 然后,在 Nushell 里我们可以从 "greetings.nu" 中导入所有定义: ```nu -> use greetings.nu * +use greetings.nu * -> hello "world" -hello world! +# => hello "world" +# => hello world! -> hi "there" -hi there! +# => hi "there" +# => hi there! -> greetings-helper "foo" "bar" # fails because 'greetings-helper' is not exported +greetings-helper "foo" "bar" # fails because 'greetings-helper' is not exported ``` ## 环境变量 @@ -159,35 +159,35 @@ export def hello [name: string] { `use` 的工作方式与自定义命令相同: ```nu -> use greetings.nu +use greetings.nu -> $env."greetings MYNAME" -Arthur, King of the Britons +# => $env."greetings MYNAME" +# => Arthur, King of the Britons -> greetings hello $env."greetings MYNAME" -hello Arthur, King of the Britons! +greetings hello $env."greetings MYNAME" +# => hello Arthur, King of the Britons! ``` 你可能注意到我们没有直接给`MYNAME`赋值,相反,我们给了它一个代码块(`{ ...}`),它在我们每次调用[`use`](/commands/docs/use.md)时都会被执行。例如,我们可以用[`random`](/commands/docs/random.md)命令来演示这一点: ```nu -> module roll { export env ROLL { random dice | into string } } +module roll { export env ROLL { random dice | into string } } -> use roll ROLL +use roll ROLL -> $env.ROLL -4 +# => $env.ROLL +# => 4 -> $env.ROLL -4 +# => $env.ROLL +# => 4 -> use roll ROLL +use roll ROLL -> $env.ROLL -6 +# => $env.ROLL +# => 6 -> $env.ROLL -6 +$env.ROLL +# => 6 ``` ## 导出符号 @@ -211,14 +211,14 @@ hello Arthur, King of the Britons! 我们用[`hide`](/commands/docs/hide.md)命令来实现隐藏: ```nu -> def foo [] { "foo" } +def foo [] { "foo" } -> foo -foo +# => foo +# => foo -> hide foo +hide foo -> foo # error! command not found! +foo # error! command not found! ``` [`hide`](/commands/docs/hide.md)命令也接受导入模式,就像[`use`](/commands/docs/use.md)那样。不过,导入模式的解释略有不同。它可以是下面中的一种: @@ -243,50 +243,50 @@ foo 让我们看几个例子。前面已经看到了直接隐藏一个自定义命令的例子,现在让我们试试环境变量: ```nu -> $env.FOO = "FOO" +$env.FOO = "FOO" -> $env.FOO -FOO +# => $env.FOO +# => FOO -> hide FOO +hide FOO -> $env.FOO # error! environment variable not found! +$env.FOO # error! environment variable not found! ``` 第一种情况也适用于从一个模块导入的命令/环境变量(使用上面定义的 "greetings.nu" 文件): ```nu -> use greetings.nu * +use greetings.nu * -> $env.MYNAME -Arthur, King of the Britons +# => $env.MYNAME +# => Arthur, King of the Britons -> hello "world" -hello world! +# => hello "world" +# => hello world! -> hide MYNAME +hide MYNAME -> $env.MYNAME # error! environment variable not found! +$env.MYNAME # error! environment variable not found! -> hide hello +hide hello -> hello "world" # error! command not found! +hello "world" # error! command not found! ``` 最后,当名称为模块名时(假设是之前的`greetings`模块): ```nu -> use greetings.nu +use greetings.nu -> $env."greetings MYNAME" -Arthur, King of the Britons +# => $env."greetings MYNAME" +# => Arthur, King of the Britons -> greetings hello "world" -hello world! +# => greetings hello "world" +# => hello world! -> hide greetings +hide greetings -> $env."greetings MYNAME" # error! environment variable not found! +$env."greetings MYNAME" # error! environment variable not found! -> greetings hello "world" # error! command not found! +greetings hello "world" # error! command not found! ``` diff --git a/zh-CN/book/operators.md b/zh-CN/book/operators.md index a14d0b3c31a..39097fb08e7 100644 --- a/zh-CN/book/operators.md +++ b/zh-CN/book/operators.md @@ -44,8 +44,8 @@ Nushell 支持以下常见的数学、逻辑和字符串操作的运算符: - 加 (`+`) 和减 (`-`) ``` -> 3 * (1 + 2) -9 +3 * (1 + 2) +# => 9 ``` ## 正则表达式 / 字符串包含运算符 diff --git a/zh-CN/book/overlays.md b/zh-CN/book/overlays.md index 7efcfd6d94b..10e9d778024 100644 --- a/zh-CN/book/overlays.md +++ b/zh-CN/book/overlays.md @@ -14,7 +14,7 @@ _注意:要了解覆层,请确保先查看 [模块](modules.md),因为覆 要创建一个新的覆层,你首先需要一个模块: ```nu -> module spam { +module spam { export def foo [] { "foo" } @@ -32,22 +32,22 @@ _注意:要了解覆层,请确保先查看 [模块](modules.md),因为覆 要创建覆层,请调用 [`overlay use`](/commands/docs/overlay_use.md)。 ```nu -> overlay use spam +overlay use spam -> foo foo +# => foo -> bar bar +# => bar -> $env.BAZ -baz +$env.BAZ +# => baz -> overlay list -───┬────── - 0 │ zero - 1 │ spam -───┴────── +overlay list +# => ───┬────── +# => 0 │ zero +# => 1 │ spam +# => ───┴────── ``` 在下面的章节中,`>` 的提示语前面会有最后一个活动覆层的名称。 diff --git a/zh-CN/book/parallelism.md b/zh-CN/book/parallelism.md index f32c6c8f5d9..c007d6a53e8 100644 --- a/zh-CN/book/parallelism.md +++ b/zh-CN/book/parallelism.md @@ -13,7 +13,7 @@ Nushell 现在已经初步支持并行运行代码了,这允许你使用更多 假设你想计算当前目录下每个子目录下的文件数量。使用[`each`](/commands/docs/each.md)你可以这样写。 ```nu -> ls | where type == dir | each { |elt| +ls | where type == dir | each { |elt| { name: $elt.name, len: (ls $elt.name | length) } } ``` @@ -25,7 +25,7 @@ Nushell 现在已经初步支持并行运行代码了,这允许你使用更多 现在,由于这个操作可以并行运行,让我们把上面的操作转换为并行的,把[`each`](/commands/docs/each.md)改为[`par-each`](/commands/docs/par-each.md): ```nu -> ls | where type == dir | par-each { |row| +ls | where type == dir | par-each { |row| { name: $row.name, len: (ls $row.name | length) } } ``` @@ -35,7 +35,7 @@ Nushell 现在已经初步支持并行运行代码了,这允许你使用更多 顺便提一下:由于 [环境变量是有作用域的](environment.md#作用域),你可以使用`par-each`在多个目录中并行工作(注意 `cd` 命令): ```nu -> ls | where type == dir | par-each { |row| +ls | where type == dir | par-each { |row| { name: $row.name, len: (cd $row.name; ls | length) } } ``` diff --git a/zh-CN/book/pipelines.md b/zh-CN/book/pipelines.md index 3848399a1cf..544f9ff0e80 100644 --- a/zh-CN/book/pipelines.md +++ b/zh-CN/book/pipelines.md @@ -7,7 +7,7 @@ Nu 的核心设计之一是管道,这个设计思想可以追溯到几十年 一个管道由三部分组成:输入、过滤器和输出。 ```nu -> open "Cargo.toml" | inc package.version --minor | save "Cargo_new.toml" +open "Cargo.toml" | inc package.version --minor | save "Cargo_new.toml" ``` 第一条命令:`open "Cargo.toml"` 是一个输入(有时也称为 "源" 或 "生产者"),它创建或加载数据,并将其送入管道。管道待处理的值正是来自于此输入。像[`ls`](/commands/docs/ls.md)这样的命令也是输入,因为它们从文件系统中获取数据,并通过管道发送以便能被后续使用。 @@ -19,8 +19,8 @@ Nu 的核心设计之一是管道,这个设计思想可以追溯到几十年 `$in` 变量可以将管道收集成一个值,允许你将整个流作为一个参数访问,比如: ```nu -> echo 1 2 3 | $in.1 * $in.2 -6 +echo 1 2 3 | $in.1 * $in.2 +# => 6 ``` ## 多行管道 @@ -60,13 +60,13 @@ Nu 在两个外部命令之间以与其他 Shell 相同的方式处理数据管 实际上,该命令: ``` -> ls +ls ``` 和以下管道: ``` -> ls | table +ls | table ``` 是一样的。 diff --git a/zh-CN/book/plugins.md b/zh-CN/book/plugins.md index b74eb85bcc2..4237fe45a14 100644 --- a/zh-CN/book/plugins.md +++ b/zh-CN/book/plugins.md @@ -11,13 +11,13 @@ Nu 的插件是可执行的;Nu 在需要时启动它们,并通过 [stdin, st Linux+macOS: ```nu -> plugin add --encoding=capnp ./my_plugins/my-cool-plugin +plugin add --encoding=capnp ./my_plugins/my-cool-plugin ``` Windows: ```nu -> plugin add --encoding=capnp .\my_plugins\my-cool-plugin.exe +plugin add --encoding=capnp .\my_plugins\my-cool-plugin.exe ``` 当 [`plugin add`](/commands/docs/plugin_add.md) 被调用时: @@ -29,7 +29,7 @@ Windows: 一旦注册,该插件就可以作为你的命令集的一部分被使用: ```nu -> help commands | where is_plugin == true +help commands | where is_plugin == true ``` ## 示例 diff --git a/zh-CN/book/scripts.md b/zh-CN/book/scripts.md index 43d04a3787d..6eb5f02c9d0 100644 --- a/zh-CN/book/scripts.md +++ b/zh-CN/book/scripts.md @@ -3,13 +3,13 @@ 在 Nushell 中,你可以用 Nushell 语言编写和运行脚本。要运行一个脚本,你可以把它作为一个参数传递给`nu`命令行程序: ```nu -> nu myscript.nu +nu myscript.nu ``` 这将在一个新的 Nu 实例中运行脚本直至完成。你也可以使用[`source`](/commands/docs/source.md)在 Nu 的 **当前** 实例中运行脚本: ```nu -> source myscript.nu +source myscript.nu ``` 我们来看一个脚本文件的例子吧: @@ -67,8 +67,8 @@ def main [x: int] { ``` ``` -> nu myscript.nu 100 -110 +nu myscript.nu 100 +# => 110 ``` ## Shebangs (`#!`) @@ -83,6 +83,6 @@ echo "Hello World!" 此时你可以直接运行该脚本(注意:前面并没有加`nu`): ```nu -> ./myscript -Hello World! +./myscript +# => Hello World! ``` diff --git a/zh-CN/book/stdout_stderr_exit_codes.md b/zh-CN/book/stdout_stderr_exit_codes.md index b3ce6c9bee7..af4fc9618a5 100644 --- a/zh-CN/book/stdout_stderr_exit_codes.md +++ b/zh-CN/book/stdout_stderr_exit_codes.md @@ -9,7 +9,7 @@ Nushell 和外部命令之间互操作的一个重要部分是与来自外部的 标准输出流(stdout)是大多数外部应用程序将数据发送到管道或屏幕上的方式。如果由外部应用发送到其 stdout 的数据是管道的一部分,Nushell 会默认接收。 ```nu -> external | str join +external | str join ``` 以上将调用名为`external`的外部命令,并将 stdout 输出流重定向到管道中。有了这个重定向,Nushell 就可以把数据传递给管道中的下一个命令,这里是`str join`。 @@ -23,7 +23,7 @@ Nushell 和外部命令之间互操作的一个重要部分是与来自外部的 你可以通过使用`do -i { ... }`来强制 Nushell 做一个重定向。例如,如果我们想调用上面的外部程序并重定向其 stderr,我们可以这样写: ```nu -> do -i { external } +do -i { external } ``` ## 退出码 @@ -33,8 +33,8 @@ Nushell 和外部命令之间互操作的一个重要部分是与来自外部的 Nushell 通过两种方式之一跟踪最近完成的外部命令的最后退出代码。第一种方式是使用`LAST_EXIT_CODE`环境变量。 ```nu -> do -i { external } -> echo $env.LAST_EXIT_CODE +do -i { external } +echo $env.LAST_EXIT_CODE ``` 第二种是使用一个叫做[`complete`](/commands/docs/complete.md)的命令。 @@ -46,12 +46,12 @@ Nushell 通过两种方式之一跟踪最近完成的外部命令的最后退出 如果我们尝试在一个不存在的文件上运行外部的`cat`,我们可以看到[`complete`](/commands/docs/complete.md)对流的处理,包括重定向的 stderr: ```nu -> do -i { cat unknown.txt } | complete -╭───────────┬─────────────────────────────────────────────╮ -│ stdout │ │ -│ stderr │ cat: unknown.txt: No such file or directory │ -│ exit_code │ 1 │ -╰───────────┴─────────────────────────────────────────────╯ +do -i { cat unknown.txt } | complete +# => ╭───────────┬─────────────────────────────────────────────╮ +# => │ stdout │ │ +# => │ stderr │ cat: unknown.txt: No such file or directory │ +# => │ exit_code │ 1 │ +# => ╰───────────┴─────────────────────────────────────────────╯ ``` ## 原始流 @@ -65,6 +65,6 @@ Nushell 试图将流转换为 UTF-8 文本,如果在任何时候转换失败 如果你想对字节流的解码有更多的控制,你可以使用 [`decode`](/commands/docs/decode.md) 命令。[`decode`](/commands/docs/decode.md)命令可以插入到外部或其他原始流创建命令之后的管道中,它将根据你给`decode`的参数来处理字节的解码。例如,你可以这样对 shift-jis 文本进行解码: ```nu -> 0x[8a 4c] | decode shift-jis -貝 +# => 0x[8a 4c] | decode shift-jis +# => 貝 ``` diff --git a/zh-CN/book/thinking_in_nu.md b/zh-CN/book/thinking_in_nu.md index 2bfda3a6dbd..4aa882a72a7 100644 --- a/zh-CN/book/thinking_in_nu.md +++ b/zh-CN/book/thinking_in_nu.md @@ -9,7 +9,7 @@ Nushell 既是一种编程语言,也是一种 Shell。正因为如此,它有自己的方式来处理文件、目录、网站等等。我们对其进行了建模,以使其与你可能熟悉的其他 Shell 的工作方式接近。其中管道用于将两个命令连接在一起: ```nu -> ls | length +ls | length ``` Nushell 也支持其他常见的功能,例如从之前运行的命令中获取退出代码(Exit Code)。 @@ -17,13 +17,13 @@ Nushell 也支持其他常见的功能,例如从之前运行的命令中获取 虽然它确实有这些功能,但 Nushell 并不是 Bash。Bash 的工作方式以及一般的 POSIX 风格,并不是 Nushell 所支持的。例如,在 Bash 中你可以使用: ```shell -> echo "hello" > output.txt +echo "hello" > output.txt ``` 在 Nushell 中,我们使用 `>` 作为大于运算符,这与 Nushell 的语言特质比较吻合。取而代之的是,你需要用管道将其连接到一个可以保存内容的命令: ```nu -> "hello" | save output.txt +"hello" | save output.txt ``` **以 Nushell 的方式思考:** Nushell 看待数据的方式是,数据在管道中流动,直到它到达用户或由最后的命令处理。你可以简单地输入数据,从字符串到类似 JSON 的列表和记录,然后使用 `|` 将其通过管道发送。Nushell 使用命令来执行工作并生成更多数据。学习这些命令以及何时使用它们有助于你组合使用多种管道。 @@ -43,33 +43,33 @@ abc ``` ```nu -> nu compiled.nu -Error: nu::parser::sourced_file_not_found - - × File not found - ╭─[.../compiled.nu:2:1] - 2 │ sleep 1sec - 3 │ source "output.nu" - · ─────┬───── - · ╰── File not found: output.nu - 4 │ abc - ╰──── - help: sourced files need to be available before your script is run +nu compiled.nu +# => Error: nu::parser::sourced_file_not_found +# => +# => × File not found +# => ╭─[.../compiled.nu:2:1] +# => 2 │ sleep 1sec +# => 3 │ source "output.nu" +# => · ─────┬───── +# => · ╰── File not found: output.nu +# => 4 │ abc +# => ╰──── +# => help: sourced files need to be available before your script is run ``` 但是,以 [组](types_of_data.html#组) 的方式在**交互式模式**中运行就又和脚本一样了: ```nu -> "def abc [] { 1 + 2 }" | save output.nu; sleep 1sec; source "output.nu"; abc -Error: nu::parser::sourced_file_not_found - - × File not found - ╭─[entry #1:1:1] - 1 │ "def abc [] { 1 + 2 }" | save output.nu; sleep 1sec; source "output.nu"; abc - · ─────┬───── - · ╰── File not found: output.nu - ╰──── - help: sourced files need to be available before your script is run +"def abc [] { 1 + 2 }" | save output.nu; sleep 1sec; source "output.nu"; abc +# => Error: nu::parser::sourced_file_not_found +# => +# => × File not found +# => ╭─[entry #1:1:1] +# => 1 │ "def abc [] { 1 + 2 }" | save output.nu; sleep 1sec; source "output.nu"; abc +# => · ─────┬───── +# => · ╰── File not found: output.nu +# => ╰──── +# => help: sourced files need to be available before your script is run ``` `source` 命令将引入被编译的源码,但前面那行 `save` 命令还没有机会运行。Nushell 运行整个程序块就像运行一个文件一样,而不是一次运行一行。在这个例子中,由于 `output.nu` 文件是在“编译”步骤之后才创建的,因此 `source` 命令在解析时无法从其中读取定义。 @@ -77,7 +77,7 @@ Error: nu::parser::sourced_file_not_found 另一个常见的问题是试图动态地创建文件名并 `source`,如下: ```nu -> source $"($my_path)/common.nu" +source $"($my_path)/common.nu" ``` 这就需要求值器(Evaluator)运行并对字符串进行求值(Evaluate),但不幸的是,Nushell 在编译时就需要这些信息。 @@ -101,13 +101,13 @@ let x = $x + 1 循环计数器是可变变量的另一种常见模式,它被内置于大多数迭代命令中,例如,你可以使用 [`each`](/commands/docs/each.md) 上的 `-n` 标志同时获得每个元素的值和索引: ```nu -> ls | enumerate | each { |elt| $"Number ($elt.index) is size ($elt.item.size)" } +ls | enumerate | each { |elt| $"Number ($elt.index) is size ($elt.item.size)" } ``` 你也可以使用 [`reduce`](/commands/docs/reduce.md) 命令来达到上述目的,其方式与你在循环中修改一个变量相同。例如,如果你想在一个字符串列表中找到最长的字符串,你可以这样做: ```nu -> [one, two, three, four, five, six] | reduce {|curr, max| +[one, two, three, four, five, six] | reduce {|curr, max| if ($curr | str length) > ($max | str length) { $curr } else { @@ -127,7 +127,7 @@ Nushell 从编译型语言中获得了很多设计灵感,其中一个是语言 在实践中,这可以让你用更简洁的代码来处理子目录,例如,如果你想在当前目录下构建每个子项目,你可以运行: ```nu -> ls | each { |row| +ls | each { |row| cd $row.name make } diff --git a/zh-CN/book/types_of_data.md b/zh-CN/book/types_of_data.md index 6e97fc90ce6..0ecbf4b7faa 100644 --- a/zh-CN/book/types_of_data.md +++ b/zh-CN/book/types_of_data.md @@ -11,7 +11,7 @@ Nu 在其命令中采用了这种方法,并将其扩展到包括其他类型 你可以通过 [`describe`](/commands/docs/describe.md) 命令获取一个值的类型: ``` -> 42 | describe +42 | describe ``` ## 整数 @@ -20,7 +20,7 @@ Nu 在其命令中采用了这种方法,并将其扩展到包括其他类型 你可以用 `into int` 命令将一个字符串转换成一个整数: ```nu -> "1" | into int +"1" | into int ``` ## 小数 @@ -29,7 +29,7 @@ Nu 在其命令中采用了这种方法,并将其扩展到包括其他类型 你可以用 `into float` 命令将一个字符串转换成一个小数: ```nu -> "1.2" | into float +"1.2" | into float ``` ## 字符串 @@ -57,23 +57,23 @@ Nu 在其命令中采用了这种方法,并将其扩展到包括其他类型 Nushell 支持字符串插值,允许你在以`$`为前缀的字符串中运行子表达式。比如: ``` -> echo $"6 x 7 = (6 * 7)" -6 x 7 = 42 +echo $"6 x 7 = (6 * 7)" +# => 6 x 7 = 42 ``` ``` -> ls | each { |elt| echo $"($elt.name) is ($elt.size)" } -───┬───────────────────── - 0 │ genawait is 4.1 KB - 1 │ learncpp is 4.1 KB - 2 │ nuscripts is 4.1 KB -───┴───────────────────── +ls | each { |elt| echo $"($elt.name) is ($elt.size)" } +# => ───┬───────────────────── +# => 0 │ genawait is 4.1 KB +# => 1 │ learncpp is 4.1 KB +# => 2 │ nuscripts is 4.1 KB +# => ───┴───────────────────── ``` **裸字符串** ``` -> echo hello +echo hello ``` Nushell 的一个独特特征是,你也可以创建一个没有任何引号的单字字符串。 @@ -81,14 +81,14 @@ Nushell 的一个独特特征是,你也可以创建一个没有任何引号的 上面的内容和如下写法是一样的: ``` -> echo "hello" +echo "hello" ``` 通过 `into ` 命令将一个字符串转换为另一种类型: ```nu -> "1" | into int -> "1.2" | into float +"1" | into int +"1.2" | into float ``` 另见 [字符串的使用](loading_data.html#处理字符串)。 @@ -199,9 +199,9 @@ Eg) `1wk`是一个星期的时间间隔。 你可以使用 `0x[...]` 、 `0b[...]` 或 `0o[...]` 的形式将二进制写成一个字面值: ``` -> 0x[1F FF] # 十六进制 -> 0b[1 1010] # 二进制 -> 0o[377] # 八进制 +0x[1F FF] # 十六进制 +0b[1 1010] # 二进制 +0o[377] # 八进制 ``` 不完整的字节将用零来填充。 @@ -215,23 +215,23 @@ Eg) `1wk`是一个星期的时间间隔。 记录(Records)持有键值对,很像 JSON 中的对象。由于这些记录有时会有很多字段,所以记录是从上到下打印的,而不是从左到右: ``` -> echo {name: sam, rank: 10} -╭──────┬─────╮ -│ name │ sam │ -│ rank │ 10 │ -╰──────┴─────╯ +echo {name: sam, rank: 10} +# => ╭──────┬─────╮ +# => │ name │ sam │ +# => │ rank │ 10 │ +# => ╰──────┴─────╯ ``` 你可以将其转换到一个表然后遍历该记录: ``` -> echo {name: sam, rank: 10} | transpose key value -╭───┬──────┬───────╮ -│ # │ key │ value │ -├───┼──────┼───────┤ -│ 0 │ name │ sam │ -│ 1 │ rank │ 10 │ -╰───┴──────┴───────╯ +echo {name: sam, rank: 10} | transpose key value +# => ╭───┬──────┬───────╮ +# => │ # │ key │ value │ +# => ├───┼──────┼───────┤ +# => │ 0 │ name │ sam │ +# => │ 1 │ rank │ 10 │ +# => ╰───┴──────┴───────╯ ``` ## 列表 @@ -241,12 +241,12 @@ Eg) `1wk`是一个星期的时间间隔。 例如,一个字符串的列表: ``` -> echo [sam fred george] -───┬──────── - 0 │ sam - 1 │ fred - 2 │ george -───┴──────── +echo [sam fred george] +# => ───┬──────── +# => 0 │ sam +# => 1 │ fred +# => 2 │ george +# => ───┴──────── ``` ## 表 @@ -256,36 +256,36 @@ Eg) `1wk`是一个星期的时间间隔。 我们可以创建自己的表,就像我们创建一个列表一样。因为表也包含列,而不仅仅是值,所以我们需要传入列的名称: ``` -> echo [[column1, column2]; [Value1, Value2]] -───┬─────────┬───────── - # │ column1 │ column2 -───┼─────────┼───────── - 0 │ Value1 │ Value2 -───┴─────────┴───────── +echo [[column1, column2]; [Value1, Value2]] +# => ───┬─────────┬───────── +# => # │ column1 │ column2 +# => ───┼─────────┼───────── +# => 0 │ Value1 │ Value2 +# => ───┴─────────┴───────── ``` 我们还可以创建一个有多行数据的表格: ``` -> echo [[column1, column2]; [Value1, Value2] [Value3, Value4]] -───┬─────────┬───────── - # │ column1 │ column2 -───┼─────────┼───────── - 0 │ Value1 │ Value2 - 1 │ Value3 │ Value4 -───┴─────────┴───────── +echo [[column1, column2]; [Value1, Value2] [Value3, Value4]] +# => ───┬─────────┬───────── +# => # │ column1 │ column2 +# => ───┼─────────┼───────── +# => 0 │ Value1 │ Value2 +# => 1 │ Value3 │ Value4 +# => ───┴─────────┴───────── ``` 你也可以通过一个记录列表来创建表格: ``` -> echo [{name: sam, rank: 10}, {name: bob, rank: 7}] -╭───┬──────┬──────╮ -│ # │ name │ rank │ -├───┼──────┼──────┤ -│ 0 │ sam │ 10 │ -│ 1 │ bob │ 7 │ -╰───┴──────┴──────╯ +echo [{name: sam, rank: 10}, {name: bob, rank: 7}] +# => ╭───┬──────┬──────╮ +# => │ # │ name │ rank │ +# => ├───┼──────┼──────┤ +# => │ 0 │ sam │ 10 │ +# => │ 1 │ bob │ 7 │ +# => ╰───┴──────┴──────╯ ``` ## 块 diff --git a/zh-CN/book/variables_and_subexpressions.md b/zh-CN/book/variables_and_subexpressions.md index 41685691edd..e9d99387911 100644 --- a/zh-CN/book/variables_and_subexpressions.md +++ b/zh-CN/book/variables_and_subexpressions.md @@ -9,20 +9,20 @@ 如果我们创建了一个变量,我们可以通过使用`$`来引用它并打印其内容: ```nu -> let my_value = 4 -> echo $my_value -4 +let my_value = 4 +echo $my_value +# => 4 ``` Nushell 中的变量是不可变的,这意味着你不能在声明后修改它的值。 不过它们可以在嵌套块中被隐藏,这导致: ```nu -> let my_value = 4 -> do { let my_value = 5; echo $my_value } -5 -> echo $my_value -4 +let my_value = 4 +do { let my_value = 5; echo $my_value } +# => 5 +echo $my_value +# => 4 ``` ## 变量路径 @@ -30,13 +30,13 @@ Nushell 中的变量是不可变的,这意味着你不能在声明后修改它 变量路径通过深入变量的内容,找到其中的列,并最终获得一个值。比如,对于前面的例子如果我们不是赋值`4`,而是赋值了一个表的值: ```nu -> let my_value = [[name]; [testuser]] +let my_value = [[name]; [testuser]] ``` 我们可以使用一个变量路径来访问变量`$my_value`并只用一步从`name`列获得数值: ```nu -> echo $my_value.name +# => > echo $my_value.name testuser ``` @@ -49,14 +49,14 @@ testuser 子表达式也可以是管道,而不仅仅是单个命令。如果我们想得到一个大于 10KB 的文件名列表,我们可以使用子表达式来运行一个管道,并将其赋值给一个变量: ```nu -> let names_of_big_files = (ls | where size > 10kb) -> echo $names_of_big_files -───┬────────────┬──────┬──────────┬────────────── - # │ name │ type │ size │ modified -───┼────────────┼──────┼──────────┼────────────── - 0 │ Cargo.lock │ File │ 155.3 KB │ 17 hours ago - 1 │ README.md │ File │ 15.9 KB │ 17 hours ago -───┴────────────┴──────┴──────────┴────────────── +let names_of_big_files = (ls | where size > 10kb) +echo $names_of_big_files +# => ───┬────────────┬──────┬──────────┬────────────── +# => # │ name │ type │ size │ modified +# => ───┼────────────┼──────┼──────────┼────────────── +# => 0 │ Cargo.lock │ File │ 155.3 KB │ 17 hours ago +# => 1 │ README.md │ File │ 15.9 KB │ 17 hours ago +# => ───┴────────────┴──────┴──────────┴────────────── ``` ## 子表达式和路径 @@ -64,13 +64,13 @@ testuser 子表达式也支持路径,例如,假设我们想获得当前目录下的文件名列表,其中一个办法是使用管道: ```nu -> ls | get name +ls | get name ``` 我们也可以使用子表达式路径只需一步即可: ```nu -> echo (ls).name +echo (ls).name ``` 这取决于代码的需要和你个人喜欢的编码风格。 @@ -80,15 +80,15 @@ testuser Nushell 支持使用一种简化的方式访问子表达式中的列,你可能已经使用过这个功能了。例如,如果我们想只看到[`ls`](/commands/docs/ls.md)中大小至少为 10KB 的行,我们可以通过: ```nu -> ls | where size > 10kb +ls | where size > 10kb ``` `where size > 10kb`是一个由两部分组成的命令:命令名[`where`](/commands/docs/where.md)和简化的表达式`size > 10kb`。我们说简化是因为这里的`size`是`$it.size`的简洁版。也可以用以下任何一种方式来写: ```nu -> ls | where $it.size > 10kb -> ls | where ($it.size > 10kb) -> ls | where {|$x| $x.size > 10kb } +ls | where $it.size > 10kb +ls | where ($it.size > 10kb) +ls | where {|$x| $x.size > 10kb } ``` 为了使简化语法正常工作,列名必须出现在操作的左侧(如`size > 10kb`中的`size`)。 diff --git a/zh-CN/book/working_with_lists.md b/zh-CN/book/working_with_lists.md index 0403b07ed4e..bdfce215e20 100644 --- a/zh-CN/book/working_with_lists.md +++ b/zh-CN/book/working_with_lists.md @@ -11,15 +11,15 @@ 当列表数据从管道流入时,你可以向列表中更新(`update`)和插入(`insert`)值,例如,让我们在列表的中间插入值`10`: ```nu -> [1, 2, 3, 4] | insert 2 10 -# [1, 2, 10, 3, 4] +[1, 2, 3, 4] | insert 2 10 +# => [1, 2, 10, 3, 4] ``` 我们也可以使用`update`将第二个元素的值替换为`10`: ```nu -> [1, 2, 3, 4] | update 1 10 -# [1, 10, 3, 4] +[1, 2, 3, 4] | update 1 10 +# => [1, 10, 3, 4] ``` 除了 `update` 和 `insert` 之外,还有 `prepend` 和 `append`,它们分别让你插入到列表的开头或列表的结尾。例如: diff --git a/zh-CN/book/working_with_strings.md b/zh-CN/book/working_with_strings.md index 6ae012cd62e..c9d95cced15 100644 --- a/zh-CN/book/working_with_strings.md +++ b/zh-CN/book/working_with_strings.md @@ -7,8 +7,8 @@ Nushell 中的字符串用于保存文本数据以便后续使用,其中可以 Nushell 中最简单的字符串是单引号字符串。这种字符串使用`'`字符来包裹文本。下面是作为单引号字符串的`hello world`示例: ```nu -> 'hello world' -hello world +'hello world' +# => hello world ``` 单引号字符串不会对它们所给予的文本做任何事情,这使得它们成为容纳广泛文本数据的理想选择。 @@ -20,9 +20,9 @@ hello world 例如,我们可以用转义字符和双引号字符串写出文字 hello,然后换行,再写上 world: ```nu -> "hello\nworld" -hello -world +"hello\nworld" +# => hello +# => world ``` 转义字符让你快速添加一个非此难以输入的字符。 @@ -49,9 +49,9 @@ Nushell 目前支持以下转义字符: 例如,假设我们有一个叫做`$name`的变量,我们想问候这个变量中所包含的人: ```nu -> let name = "Alice" -> $"greetings, ($name)" -greetings, Alice +let name = "Alice" +$"greetings, ($name)" +# => greetings, Alice ``` 通过使用`()`包裹表达式,我们可以运行它们并使用结果来帮助生成字符串。 @@ -61,8 +61,8 @@ greetings, Alice 从 0.61 版开始,字符串插值支持转义小括号,所以`(`和`)`字符可以在一个字符串中使用,而 Nushell 不会试图计算它们之间出现的内容: ```nu -> $"2 + 2 is (2 + 2) \(you guessed it!)" -2 + 2 is 4 (you guessed it!) +$"2 + 2 is (2 + 2) \(you guessed it!)" +# => 2 + 2 is 4 (you guessed it!) ``` ## 分割字符串 @@ -81,8 +81,8 @@ greetings, Alice 例如, 你可以使用`str contains`来检查一个字符串是否包含某个特定的字符: ```nu -> "hello world" | str contains "w" -true +"hello world" | str contains "w" +# => true ``` ### 修剪字符串 @@ -90,8 +90,8 @@ true 你可以用 [`str trim`](/commands/docs/str_trim.md) 命令修剪字符串的两侧。默认情况下,[`str trim`](/commands/docs/str_trim.md) 命令会修剪字符串两边的空白。比如: ```nu -> ' My string ' | str trim -My string +' My string ' | str trim +# => My string ``` 你可以用 `--right` 和 `--left` 选项来指定对哪一边进行修剪。 @@ -101,8 +101,8 @@ My string 下面是一个传入了所有选项的例子: ```nu -> '=== Nu shell ===' | str trim -r -c '=' -=== Nu shell +'=== Nu shell ===' | str trim -r -c '=' +# => === Nu shell ``` ### 子字符串 @@ -110,12 +110,12 @@ My string 子字符串是一个字符串的切片,它们有起始点和结束点。下面是一个使用子串的例子: ```nu -> 'Hello World!' | str index-of 'o' -4 -> 'Hello World!' | str index-of 'r' -8 -> 'Hello World!' | str substring 4..8 -o Wo +'Hello World!' | str index-of 'o' +# => 4 +'Hello World!' | str index-of 'r' +# => 8 +'Hello World!' | str substring 4..8 +# => o Wo ``` ### 字符串填充 @@ -123,10 +123,10 @@ o Wo [`fill`](/commands/docs/fill.md): ```nu -> '1234' | fill -a right -c '0' -w 10 -0000001234 -> '1234' | fill -a left -c '0' -w 10 | str length -10 +'1234' | fill -a right -c '0' -w 10 +# => 0000001234 +'1234' | fill -a left -c '0' -w 10 | str length +# => 10 ``` ### 反转字符串 @@ -134,14 +134,14 @@ o Wo 反转字符串可以通过 [`str reverse`](/commands/docs/str_reverse.md) 命令轻松完成: ```nu -> 'Nushell' | str reverse -llehsuN -> ['Nushell' 'is' 'cool'] | str reverse -╭───┬─────────╮ -│ 0 │ llehsuN │ -│ 1 │ si │ -│ 2 │ looc │ -╰───┴─────────╯ +'Nushell' | str reverse +# => llehsuN +['Nushell' 'is' 'cool'] | str reverse +# => ╭───┬─────────╮ +# => │ 0 │ llehsuN │ +# => │ 1 │ si │ +# => │ 2 │ looc │ +# => ╰───┴─────────╯ ``` ## 解析字符串 @@ -149,18 +149,18 @@ llehsuN 通过 [`parse`](/commands/docs/parse.md) 命令,你可以将一个字符串解析成若干列。比如: ```nu -> 'Nushell is the best' | parse '{shell} is {type}' -╭───┬─────────┬──────────╮ -│ # │ shell │ type │ -├───┼─────────┼──────────┤ -│ 0 │ Nushell │ the best │ -╰───┴─────────┴──────────╯ -> 'Bash is kinda cringe' | parse --regex '(?P\w+) is (?P[\w\s]+)' -╭───┬───────┬──────────────╮ -│ # │ shell │ type │ -├───┼───────┼──────────────┤ -│ 0 │ Bash │ kinda cringe │ -╰───┴───────┴──────────────╯ +'Nushell is the best' | parse '{shell} is {type}' +# => ╭───┬─────────┬──────────╮ +# => │ # │ shell │ type │ +# => ├───┼─────────┼──────────┤ +# => │ 0 │ Nushell │ the best │ +# => ╰───┴─────────┴──────────╯ +'Bash is kinda cringe' | parse --regex '(?P\w+) is (?P[\w\s]+)' +# => ╭───┬───────┬──────────────╮ +# => │ # │ shell │ type │ +# => ├───┼───────┼──────────────┤ +# => │ 0 │ Bash │ kinda cringe │ +# => ╰───┴───────┴──────────────╯ ``` ## 字符串转换 @@ -181,7 +181,7 @@ llehsuN 你可以通过 [`ansi`](/commands/docs/ansi.md) 命令给字符串着色。例如: ```nu -> $'(ansi purple_bold)This text is a bold purple!(ansi reset)' +$'(ansi purple_bold)This text is a bold purple!(ansi reset)' ``` `ansi purple_bold` 使文本紫色加粗 diff --git a/zh-CN/book/working_with_tables.md b/zh-CN/book/working_with_tables.md index 5f68cde87b1..bb5eaefbbcd 100644 --- a/zh-CN/book/working_with_tables.md +++ b/zh-CN/book/working_with_tables.md @@ -5,18 +5,18 @@ 首先,让我们获得一个可用的表: ``` -> ls -───┬───────────────┬──────┬─────────┬──────────── - # │ name │ type │ size │ modified -───┼───────────────┼──────┼─────────┼──────────── - 0 │ files.rs │ File │ 4.6 KB │ 5 days ago - 1 │ lib.rs │ File │ 330 B │ 5 days ago - 2 │ lite_parse.rs │ File │ 6.3 KB │ 5 days ago - 3 │ parse.rs │ File │ 49.8 KB │ 1 day ago - 4 │ path.rs │ File │ 2.1 KB │ 5 days ago - 5 │ shapes.rs │ File │ 4.7 KB │ 5 days ago - 6 │ signature.rs │ File │ 1.2 KB │ 5 days ago -───┴───────────────┴──────┴─────────┴──────────── +ls +# => ───┬───────────────┬──────┬─────────┬──────────── +# => # │ name │ type │ size │ modified +# => ───┼───────────────┼──────┼─────────┼──────────── +# => 0 │ files.rs │ File │ 4.6 KB │ 5 days ago +# => 1 │ lib.rs │ File │ 330 B │ 5 days ago +# => 2 │ lite_parse.rs │ File │ 6.3 KB │ 5 days ago +# => 3 │ parse.rs │ File │ 49.8 KB │ 1 day ago +# => 4 │ path.rs │ File │ 2.1 KB │ 5 days ago +# => 5 │ shapes.rs │ File │ 4.7 KB │ 5 days ago +# => 6 │ signature.rs │ File │ 1.2 KB │ 5 days ago +# => ───┴───────────────┴──────┴─────────┴──────────── ``` ## 排序 @@ -24,18 +24,18 @@ 我们可以通过调用[`sort-by`](/commands/docs/sort-by.md)命令对一个表进行排序,并指定需要排序的列。比如,按照文件的大小对表格进行排序: ``` -> ls | sort-by size -───┬───────────────┬──────┬─────────┬──────────── - # │ name │ type │ size │ modified -───┼───────────────┼──────┼─────────┼──────────── - 0 │ lib.rs │ File │ 330 B │ 5 days ago - 1 │ signature.rs │ File │ 1.2 KB │ 5 days ago - 2 │ path.rs │ File │ 2.1 KB │ 5 days ago - 3 │ files.rs │ File │ 4.6 KB │ 5 days ago - 4 │ shapes.rs │ File │ 4.7 KB │ 5 days ago - 5 │ lite_parse.rs │ File │ 6.3 KB │ 5 days ago - 6 │ parse.rs │ File │ 49.8 KB │ 1 day ago -───┴───────────────┴──────┴─────────┴──────────── +ls | sort-by size +# => ───┬───────────────┬──────┬─────────┬──────────── +# => # │ name │ type │ size │ modified +# => ───┼───────────────┼──────┼─────────┼──────────── +# => 0 │ lib.rs │ File │ 330 B │ 5 days ago +# => 1 │ signature.rs │ File │ 1.2 KB │ 5 days ago +# => 2 │ path.rs │ File │ 2.1 KB │ 5 days ago +# => 3 │ files.rs │ File │ 4.6 KB │ 5 days ago +# => 4 │ shapes.rs │ File │ 4.7 KB │ 5 days ago +# => 5 │ lite_parse.rs │ File │ 6.3 KB │ 5 days ago +# => 6 │ parse.rs │ File │ 49.8 KB │ 1 day ago +# => ───┴───────────────┴──────┴─────────┴──────────── ``` 我们可以通过任何可以比较的列来对一个表进行排序。例如,我们也可以用 "name", "accessed" 或者 "modified" 列对上述内容进行排序。 @@ -45,33 +45,33 @@ 我们可以从表中通过选择特定的列或行来获得数据。让我们从表中选择([`select`](/commands/docs/select.md))几列吧: ``` -> ls | select name size -───┬───────────────┬───────── - # │ name │ size -───┼───────────────┼───────── - 0 │ files.rs │ 4.6 KB - 1 │ lib.rs │ 330 B - 2 │ lite_parse.rs │ 6.3 KB - 3 │ parse.rs │ 49.8 KB - 4 │ path.rs │ 2.1 KB - 5 │ shapes.rs │ 4.7 KB - 6 │ signature.rs │ 1.2 KB -───┴───────────────┴───────── +ls | select name size +# => ───┬───────────────┬───────── +# => # │ name │ size +# => ───┼───────────────┼───────── +# => 0 │ files.rs │ 4.6 KB +# => 1 │ lib.rs │ 330 B +# => 2 │ lite_parse.rs │ 6.3 KB +# => 3 │ parse.rs │ 49.8 KB +# => 4 │ path.rs │ 2.1 KB +# => 5 │ shapes.rs │ 4.7 KB +# => 6 │ signature.rs │ 1.2 KB +# => ───┴───────────────┴───────── ``` 这有助于创建一个更专注于我们所需的表格。接下来,假设我们只想看这个目录中最小的 5 个文件: ``` -> ls | sort-by size | first 5 -───┬──────────────┬──────┬────────┬──────────── - # │ name │ type │ size │ modified -───┼──────────────┼──────┼────────┼──────────── - 0 │ lib.rs │ File │ 330 B │ 5 days ago - 1 │ signature.rs │ File │ 1.2 KB │ 5 days ago - 2 │ path.rs │ File │ 2.1 KB │ 5 days ago - 3 │ files.rs │ File │ 4.6 KB │ 5 days ago - 4 │ shapes.rs │ File │ 4.7 KB │ 5 days ago -───┴──────────────┴──────┴────────┴──────────── +ls | sort-by size | first 5 +# => ───┬──────────────┬──────┬────────┬──────────── +# => # │ name │ type │ size │ modified +# => ───┼──────────────┼──────┼────────┼──────────── +# => 0 │ lib.rs │ File │ 330 B │ 5 days ago +# => 1 │ signature.rs │ File │ 1.2 KB │ 5 days ago +# => 2 │ path.rs │ File │ 2.1 KB │ 5 days ago +# => 3 │ files.rs │ File │ 4.6 KB │ 5 days ago +# => 4 │ shapes.rs │ File │ 4.7 KB │ 5 days ago +# => ───┴──────────────┴──────┴────────┴──────────── ``` 你会注意到我们首先按大小对表进行排序以得到最小的文件,然后我们用`first 5`来返回表的前 5 行。 @@ -79,14 +79,14 @@ 你也可以跳过(`skip`)不需要的行,让我们跳过上面所得 5 行中的前两行: ``` -> ls | sort-by size | first 5 | skip 2 -───┬───────────┬──────┬────────┬──────────── - # │ name │ type │ size │ modified -───┼───────────┼──────┼────────┼──────────── - 0 │ path.rs │ File │ 2.1 KB │ 5 days ago - 1 │ files.rs │ File │ 4.6 KB │ 5 days ago - 2 │ shapes.rs │ File │ 4.7 KB │ 5 days ago -───┴───────────┴──────┴────────┴──────────── +ls | sort-by size | first 5 | skip 2 +# => ───┬───────────┬──────┬────────┬──────────── +# => # │ name │ type │ size │ modified +# => ───┼───────────┼──────┼────────┼──────────── +# => 0 │ path.rs │ File │ 2.1 KB │ 5 days ago +# => 1 │ files.rs │ File │ 4.6 KB │ 5 days ago +# => 2 │ shapes.rs │ File │ 4.7 KB │ 5 days ago +# => ───┴───────────┴──────┴────────┴──────────── ``` 我们已将其缩小为我们关心的三行。 @@ -94,25 +94,25 @@ 让我们看看其他几个用于选择数据的命令。您可能想知道为什么选取表格的行是通过数字,这是选择单行数据的便捷方式。让我们按文件名对表进行排序,然后使用 `select` 命令通过行号来选择其中的一行: ``` -> ls | sort-by name -───┬───────────────┬──────┬─────────┬──────────── - # │ name │ type │ size │ modified -───┼───────────────┼──────┼─────────┼──────────── - 0 │ files.rs │ File │ 4.6 KB │ 5 days ago - 1 │ lib.rs │ File │ 330 B │ 5 days ago - 2 │ lite_parse.rs │ File │ 6.3 KB │ 5 days ago - 3 │ parse.rs │ File │ 49.8 KB │ 1 day ago - 4 │ path.rs │ File │ 2.1 KB │ 5 days ago - 5 │ shapes.rs │ File │ 4.7 KB │ 5 days ago - 6 │ signature.rs │ File │ 1.2 KB │ 5 days ago -───┴───────────────┴──────┴─────────┴──────────── +ls | sort-by name +# => ───┬───────────────┬──────┬─────────┬──────────── +# => # │ name │ type │ size │ modified +# => ───┼───────────────┼──────┼─────────┼──────────── +# => 0 │ files.rs │ File │ 4.6 KB │ 5 days ago +# => 1 │ lib.rs │ File │ 330 B │ 5 days ago +# => 2 │ lite_parse.rs │ File │ 6.3 KB │ 5 days ago +# => 3 │ parse.rs │ File │ 49.8 KB │ 1 day ago +# => 4 │ path.rs │ File │ 2.1 KB │ 5 days ago +# => 5 │ shapes.rs │ File │ 4.7 KB │ 5 days ago +# => 6 │ signature.rs │ File │ 1.2 KB │ 5 days ago +# => ───┴───────────────┴──────┴─────────┴──────────── -> ls | sort-by name | select 5 -───┬───────────────┬──────┬─────────┬──────────── - # │ name │ type │ size │ modified -───┼───────────────┼──────┼─────────┼──────────── - 0 │ shapes.rs │ File │ 4.7 KB │ 5 days ago -───┴───────────────┴──────┴─────────┴──────────── +ls | sort-by name | select 5 +# => ───┬───────────────┬──────┬─────────┬──────────── +# => # │ name │ type │ size │ modified +# => ───┼───────────────┼──────┼─────────┼──────────── +# => 0 │ shapes.rs │ File │ 4.7 KB │ 5 days ago +# => ───┴───────────────┴──────┴─────────┴──────────── ``` ## 从表格提取数据 @@ -120,16 +120,16 @@ 到目前为止,我们在处理表格时都是将表格修剪成我们需要的样子。有时我们可能想更进一步,只看单元格本身的值,而不是取整列。比如,我们只想得到一个包含所有文件名的列表。在此,我们使用[`get`](/commands/docs/get.md) 命令: ``` -> ls | get name -───┬─────────────── - 0 │ files.rs - 1 │ lib.rs - 2 │ lite_parse.rs - 3 │ parse.rs - 4 │ path.rs - 5 │ shapes.rs - 6 │ signature.rs -───┴─────────────── +ls | get name +# => ───┬─────────────── +# => 0 │ files.rs +# => 1 │ lib.rs +# => 2 │ lite_parse.rs +# => 3 │ parse.rs +# => 4 │ path.rs +# => 5 │ shapes.rs +# => 6 │ signature.rs +# => ───┴─────────────── ``` 现在我们获得了每一个文件的文件名。 @@ -137,18 +137,18 @@ 这可能看起来很像我们之前使用的[`select`](/commands/docs/select.md)命令,所以也把它放在这里以便于比较: ``` -> ls | select name -───┬─────────────── - # │ name -───┼─────────────── - 0 │ files.rs - 1 │ lib.rs - 2 │ lite_parse.rs - 3 │ parse.rs - 4 │ path.rs - 5 │ shapes.rs - 6 │ signature.rs -───┴─────────────── +ls | select name +# => ───┬─────────────── +# => # │ name +# => ───┼─────────────── +# => 0 │ files.rs +# => 1 │ lib.rs +# => 2 │ lite_parse.rs +# => 3 │ parse.rs +# => 4 │ path.rs +# => 5 │ shapes.rs +# => 6 │ signature.rs +# => ───┴─────────────── ``` 这看起来非常相似!让我们看看能不能把这两个命令的区别说清楚: @@ -169,15 +169,15 @@ 我们可以使用[`append`](/commands/docs/append.md)将列名相同的表拼接起来: ``` -> let $first = [[a b]; [1 2]] -> let $second = [[a b]; [3 4]] -> $first | append $second -───┬───┬─── - # │ a │ b -───┼───┼─── - 0 │ 1 │ 2 - 1 │ 3 │ 4 -───┴───┴─── +let $first = [[a b]; [1 2]] +let $second = [[a b]; [3 4]] +$first | append $second +# => ───┬───┬─── +# => # │ a │ b +# => ───┼───┼─── +# => 0 │ 1 │ 2 +# => 1 │ 3 │ 4 +# => ───┴───┴─── ``` ### 合并表格 @@ -185,42 +185,42 @@ 我们可以使用[`merge`](/commands/docs/merge.md)命令将两个(或多个)表格合并在一起: ```nu -> let $first = [[a b]; [1 2]] -> let $second = [[c d]; [3 4]] -> $first | merge { $second } -───┬───┬───┬───┬─── - # │ a │ b │ c │ d -───┼───┼───┼───┼─── - 0 │ 1 │ 2 │ 3 │ 4 -───┴───┴───┴───┴─── +let $first = [[a b]; [1 2]] +let $second = [[c d]; [3 4]] +$first | merge { $second } +# => ───┬───┬───┬───┬─── +# => # │ a │ b │ c │ d +# => ───┼───┼───┼───┼─── +# => 0 │ 1 │ 2 │ 3 │ 4 +# => ───┴───┴───┴───┴─── ``` 让我们再加一个表格吧: ```nu -> let $third = [[e f]; [5 6]] +let $third = [[e f]; [5 6]] ``` 我们可以将以上三个表格合并在一起,操作如下: ```nu -> $first | merge { $second } | merge { $third } -───┬───┬───┬───┬───┬───┬─── - # │ a │ b │ c │ d │ e │ f -───┼───┼───┼───┼───┼───┼─── - 0 │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 -───┴───┴───┴───┴───┴───┴─── +$first | merge { $second } | merge { $third } +# => ───┬───┬───┬───┬───┬───┬─── +# => # │ a │ b │ c │ d │ e │ f +# => ───┼───┼───┼───┼───┼───┼─── +# => 0 │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 +# => ───┴───┴───┴───┴───┴───┴─── ``` 或者我们可以使用[`reduce`](/commands/docs/reduce.md)命令来动态地合并所有的表格: ```nu -> [$first $second $third] | reduce {|elt, acc| $acc | merge { $elt }} -───┬───┬───┬───┬───┬───┬─── - # │ a │ b │ c │ d │ e │ f -───┼───┼───┼───┼───┼───┼─── - 0 │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 -───┴───┴───┴───┴───┴───┴─── +[$first $second $third] | reduce {|elt, acc| $acc | merge { $elt }} +# => ───┬───┬───┬───┬───┬───┬─── +# => # │ a │ b │ c │ d │ e │ f +# => ───┼───┼───┼───┼───┼───┼─── +# => 0 │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 +# => ───┴───┴───┴───┴───┴───┴─── ``` ### 添加新列 @@ -228,40 +228,40 @@ 我们可以使用[`insert`](/commands/docs/insert.md)命令在表中增加新列,让我们看一个例子: ``` -> open rustfmt.toml -─────────┬────── - edition │ 2018 -─────────┴────── +open rustfmt.toml +# => ─────────┬────── +# => edition │ 2018 +# => ─────────┴────── ``` 让我们添加一个名为 "next_edition" 的列并将 2021 作为值: ``` -> open rustfmt.toml | insert next_edition 2021 -──────────────┬────── - edition │ 2018 - next_edition │ 2021 -──────────────┴────── +open rustfmt.toml | insert next_edition 2021 +# => ──────────────┬────── +# => edition │ 2018 +# => next_edition │ 2021 +# => ──────────────┴────── ``` 注意,我们如果打开原始文件,会发现内容没变: ``` -> open rustfmt.toml -─────────┬────── - edition │ 2018 -─────────┴────── +open rustfmt.toml +# => ─────────┬────── +# => edition │ 2018 +# => ─────────┴────── ``` Nu 的更改是函数性更改,这意味着它们只在值上起作用,而不是试图引起永久性变更。这使我们可以在管道中进行许多不同类型的操作直到我们准备好将结果输出(如果我们选择这样做的话)。这里我们可以使用 [`save`](/commands/docs/save.md) 命令保存结果: ``` -> open rustfmt.toml | insert next_edition 2021 | save rustfmt2.toml -> open rustfmt2.toml -──────────────┬────── - edition │ 2018 - next_edition │ 2021 -──────────────┴────── +open rustfmt.toml | insert next_edition 2021 | save rustfmt2.toml +open rustfmt2.toml +# => ──────────────┬────── +# => edition │ 2018 +# => next_edition │ 2021 +# => ──────────────┴────── ``` ### 更新一列 @@ -269,19 +269,19 @@ Nu 的更改是函数性更改,这意味着它们只在值上起作用,而 与[`insert`](/commands/docs/insert.md)命令类似,我们也可以使用[`update`](/commands/docs/update.md)命令将某一列的内容修改为新值。为了看看效果,让我们打开同一个文件: ``` -> open rustfmt.toml -─────────┬────── - edition │ 2018 -─────────┴────── +open rustfmt.toml +# => ─────────┬────── +# => edition │ 2018 +# => ─────────┴────── ``` 现在,用我们希望支持的下一个版本更新 edition: ``` -> open rustfmt.toml | update edition 2021 -─────────┬────── - edition │ 2021 -─────────┴────── +open rustfmt.toml | update edition 2021 +# => ─────────┬────── +# => edition │ 2021 +# => ─────────┴────── ``` 你也可以使用[`upsert`](/commands/docs/upsert.md)命令来插入或更新,这取决于该列是否已经存在。 @@ -291,16 +291,16 @@ Nu 的更改是函数性更改,这意味着它们只在值上起作用,而 你可以使用`move`来移动表中的列。例如,如果想把`ls`中的 "name" 列移到 "size" 列之后,我们可以这样做: ``` -> ls | move name --after size -╭────┬──────┬─────────┬───────────────────┬──────────────╮ -│ # │ type │ size │ name │ modified │ -├────┼──────┼─────────┼───────────────────┼──────────────┤ -│ 0 │ dir │ 256 B │ Applications │ 3 days ago │ -│ 1 │ dir │ 256 B │ Data │ 2 weeks ago │ -│ 2 │ dir │ 448 B │ Desktop │ 2 hours ago │ -│ 3 │ dir │ 192 B │ Disks │ a week ago │ -│ 4 │ dir │ 416 B │ Documents │ 4 days ago │ -... +ls | move name --after size +# => ╭────┬──────┬─────────┬───────────────────┬──────────────╮ +# => │ # │ type │ size │ name │ modified │ +# => ├────┼──────┼─────────┼───────────────────┼──────────────┤ +# => │ 0 │ dir │ 256 B │ Applications │ 3 days ago │ +# => │ 1 │ dir │ 256 B │ Data │ 2 weeks ago │ +# => │ 2 │ dir │ 448 B │ Desktop │ 2 hours ago │ +# => │ 3 │ dir │ 192 B │ Disks │ a week ago │ +# => │ 4 │ dir │ 416 B │ Documents │ 4 days ago │ +# => ... ``` ### 重命名列 @@ -308,14 +308,14 @@ Nu 的更改是函数性更改,这意味着它们只在值上起作用,而 你也可以通过`rename`命令对表中的列进行**重命名**。我们可以使用这个例子来运行`ls`并重命名这些列: ``` -> ls | rename filename filetype filesize date -╭────┬───────────────────┬──────────┬──────────┬──────────────╮ -│ # │ filename │ filetype │ filesize │ date │ -├────┼───────────────────┼──────────┼──────────┼──────────────┤ -│ 0 │ Applications │ dir │ 256 B │ 3 days ago │ -│ 1 │ Data │ dir │ 256 B │ 2 weeks ago │ -│ 2 │ Desktop │ dir │ 448 B │ 2 hours ago │ -│ 3 │ Disks │ dir │ 192 B │ a week ago │ -│ 4 │ Documents │ dir │ 416 B │ 4 days ago │ -... +ls | rename filename filetype filesize date +# => ╭────┬───────────────────┬──────────┬──────────┬──────────────╮ +# => │ # │ filename │ filetype │ filesize │ date │ +# => ├────┼───────────────────┼──────────┼──────────┼──────────────┤ +# => │ 0 │ Applications │ dir │ 256 B │ 3 days ago │ +# => │ 1 │ Data │ dir │ 256 B │ 2 weeks ago │ +# => │ 2 │ Desktop │ dir │ 448 B │ 2 hours ago │ +# => │ 3 │ Disks │ dir │ 192 B │ a week ago │ +# => │ 4 │ Documents │ dir │ 416 B │ 4 days ago │ +# => ... ``` From 6b0200098bad2ba1d0fe70ad6f1eb1f05d608340 Mon Sep 17 00:00:00 2001 From: Joshua <67082011+0x4D5352@users.noreply.github.com> Date: Sun, 22 Dec 2024 17:17:14 -0600 Subject: [PATCH 2/3] Update zh-CN/book/dataframes.md Co-authored-by: Douglas <32344964+NotTheDr01ds@users.noreply.github.com> --- zh-CN/book/dataframes.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/zh-CN/book/dataframes.md b/zh-CN/book/dataframes.md index 2531847ecec..de310f0f744 100644 --- a/zh-CN/book/dataframes.md +++ b/zh-CN/book/dataframes.md @@ -14,10 +14,10 @@ 在这个小的性能测试练习中,我们将比较本地的 Nushell 原生命令、Nushell DataFrame 相关命令和[Python Pandas](https://pandas.pydata.org/)命令。暂时不要太在意`dataframe`命令,它们将在本页后面的章节中解释。 -系统细节:本节介绍的性能测试是用一台配备 Intel(R) Core(TM) i7-10710U -(CPU @1.10GHz 1.61GHz)和 16 GB 内存的机器运行的。 - -所有的例子都在 Nushell 0.78 版本上运行。 +> 系统细节:本节介绍的性能测试是用一台配备 Intel(R) Core(TM) i7-10710U +> (CPU @1.10GHz 1.61GHz)和 16 GB 内存的机器运行的。 +> +> 所有的例子都在 Nushell 0.78 版本上运行。 ### 文件信息 From 1c96e783bc756519de65f6190a4d73be36fa1e2f Mon Sep 17 00:00:00 2001 From: Joshua <67082011+0x4D5352@users.noreply.github.com> Date: Sun, 22 Dec 2024 17:17:21 -0600 Subject: [PATCH 3/3] Update zh-CN/book/environment.md Co-authored-by: Douglas <32344964+NotTheDr01ds@users.noreply.github.com> --- zh-CN/book/environment.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zh-CN/book/environment.md b/zh-CN/book/environment.md index 5883cf27a8a..77633600e50 100644 --- a/zh-CN/book/environment.md +++ b/zh-CN/book/environment.md @@ -213,7 +213,7 @@ $env.FOO = 'BAR' do { hide FOO # $env.FOO does not exist - } +} $env.FOO # => BAR ```