nushell/nushell

GitHub: nushell/nushell

一款基于结构化数据管道的新一代跨平台 Shell,用 Rust 编写,让命令行数据处理更直观高效。

Stars: 38570 | Forks: 2062

# Nushell [![Crates.io](https://img.shields.io/crates/v/nu.svg)](https://crates.io/crates/nu) [![Build Status](https://img.shields.io/github/actions/workflow/status/nushell/nushell/ci.yml?branch=main)](https://github.com/nushell/nushell/actions) [![Nightly Build](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/f92360d534194359.svg)](https://github.com/nushell/nushell/actions/workflows/nightly-build.yml) [![Discord](https://img.shields.io/discord/601130461678272522.svg?logo=discord)](https://discord.gg/NtAbbGn) [![The Changelog #363](https://img.shields.io/badge/The%20Changelog-%23363-61c192.svg)](https://changelog.com/podcast/363) [![GitHub commit activity](https://img.shields.io/github/commit-activity/m/nushell/nushell)](https://github.com/nushell/nushell/graphs/commit-activity) [![GitHub contributors](https://img.shields.io/github/contributors/nushell/nushell)](https://github.com/nushell/nushell/graphs/contributors) 一种新型的 shell。 ![Example of nushell](assets/nushell-autocomplete6.gif "Example of nushell") ## 目录 - [状态](#status) - [了解 Nu](#learning-about-nu) - [安装](#installation) - [配置](#configuration) - [理念](#philosophy) - [Pipelines (管道)](#pipelines) - [打开文件](#opening-files) - [插件](#plugins) - [目标](#goals) - [官方支持](#officially-supported-by) - [贡献](#contributing) - [许可证](#license) ## 状态 本项目已达到最小可行产品 (MVP) 级别的质量。许多人将其作为主力工具使用,但某些命令可能不稳定。Nu 的设计随其成熟可能会发生变化。 ## 了解 Nu [Nushell book](https://www.nushell.sh/book/) 是 Nushell 文档的主要来源。你可以在[书中找到 Nu 命令的完整列表](https://www.nushell.sh/commands/),我们在[ cookbook (指南) ](https://www.nushell.sh/cookbook/)中也有许多使用 Nu 的示例。 我们也活跃于 [Discord](https://discord.gg/NtAbbGn);欢迎来与我们交流! ## 安装 要快速安装 Nu: ``` # Linux 和 macOS brew install nushell # Windows winget install nushell ``` 要在 GitHub Action 中使用 `Nu`,请查看 [setup-nu](https://github.com/marketplace/actions/setup-nu) 获取更多详情。 详细的安装说明可以在[本书的安装章节](https://www.nushell.sh/book/installation.html)中找到。Nu 可通过许多包管理器安装: [![Packaging status](https://repology.org/badge/vertical-allrepos/nushell.svg?columns=3)](https://repology.org/project/nushell/versions) 有关 Nushell 团队积极支持哪些平台的详细信息,请参阅[我们的平台支持政策](devdocs/PLATFORM_SUPPORT.md)。 ## 配置 默认配置可以在 [sample_config](crates/nu-utils/src/default_files) 中找到 这些是首次启动 Nushell 时生成的配置文件。 它设置了运行 Nushell 的所有默认配置。用户可以在此基础上 根据特定需求自定义此文件。 要查看 *config.nu* 在你系统上的位置,只需输入以下命令。 ``` $nu.config-path ``` 请参阅我们的[ book (文档) ](https://www.nushell.sh) 获取所有 Nushell 文档。 ## 理念 Nu 从 PowerShell、函数式编程语言和现代 CLI 工具等项目中汲取了灵感。 Nu 不将文件和数据视为原始文本流,而是将每个输入视为具有结构的内容。 例如,当你列出目录的内容时,你得到的是一个行表,其中每一行代表该目录中的一个项目。 这些值可以通过一系列步骤在管道中传输,这一系列命令被称为“ pipeline (管道) ”。 ### Pipelines (管道) 在 Unix 中,在命令之间通过管道传输以将复杂的命令拆分为多个步骤是很常见的。 Nu 在此基础上更进一步,非常重视 _pipelines_ 的概念。 正如 Unix 哲学一样,Nu 允许命令输出到 stdout 并从 stdin 读取。 此外,命令可以输出结构化数据(你可以将其视为第三种流)。 在 pipeline 中工作的命令属于以下三类之一: - 产生流的命令(例如 `ls`) - 过滤流的命令(例如 `where type == "dir"`) - 消耗 pipeline 输出的命令(例如 `table`) 命令之间用管道符号 (`|`) 分隔,以表示从左到右流动的 pipeline。 ``` ls | where type == "dir" | table # => ╭────┬──────────┬──────┬─────────┬───────────────╮ # => │ # │ name │ type │ size │ modified │ # => ├────┼──────────┼──────┼─────────┼───────────────┤ # => │ 0 │ .cargo │ dir │ 0 B │ 9 分钟前 │ # => │ 1 │ assets │ dir │ 0 B │ 2 周前 │ # => │ 2 │ crates │ dir │ 4.0 KiB │ 2 周前 │ # => │ 3 │ docker │ dir │ 0 B │ 2 周前 │ # => │ 4 │ docs │ dir │ 0 B │ 2 周前 │ # => │ 5 │ images │ dir │ 0 B │ 2 周前 │ # => │ 6 │ pkg_mgrs │ dir │ 0 B │ 2 周前 │ # => │ 7 │ samples │ dir │ 0 B │ 2 周前 │ # => │ 8 │ src │ dir │ 4.0 KiB │ 2 周前 │ # => │ 9 │ target │ dir │ 0 B │ 1 天前 │ # => │ 10 │ tests │ dir │ 4.0 KiB │ 2 周前 │ # => │ 11 │ wix │ dir │ 0 B │ 2 周前 │ # => ╰────┴──────────┴──────┴─────────┴───────────────╯ ``` 因为大多数时候你会希望看到 pipeline 的输出,所以默认假定为 `table`。 我们也可以这样写上面的命令: ``` ls | where type == "dir" ``` 能够使用相同的命令并以不同的方式组合它们是 Nu 的一个重要理念。 例如,我们可以使用内置的 `ps` 命令获取正在运行的进程列表,并像上面一样使用 `where`。 ``` ps | where cpu > 0 # => ╭───┬───────┬───────────┬───────┬───────────┬───────────╮ # => │ # │ pid │ name │ cpu │ mem │ virtual │ # => ├───┼───────┼───────────┼───────┼───────────┼───────────┤ # => │ 0 │ 2240 │ Slack.exe │ 16.40 │ 178.3 MiB │ 232.6 MiB │ # => │ 1 │ 16948 │ Slack.exe │ 16.32 │ 205.0 MiB │ 197.9 MiB │ # => │ 2 │ 17700 │ nu.exe │ 3.77 │ 26.1 MiB │ 8.8 MiB │ # => ╰───┴───────┴───────────┴───────┴───────────┴───────────╯ ``` ### 打开文件 Nu 可以将文件和 URL 内容作为原始文本或结构化数据加载(如果它识别该格式)。 例如,你可以将 .toml 文件作为结构化数据加载并对其进行浏览: ``` open Cargo.toml # => ╭──────────────────┬────────────────────╮ # => │ bin │ [table 1 row] │ # => │ dependencies │ {record 25 fields} │ # => │ dev-dependencies │ {record 8 fields} │ # => │ features │ {record 10 fields} │ # => │ package │ {record 13 fields} │ # => │ patch │ {record 1 field} │ # => │ profile │ {record 3 fields} │ # => │ target │ {record 3 fields} │ # => │ workspace │ {record 1 field} │ # => ╰──────────────────┴────────────────────╯ ``` 我们可以将其通过管道传输到一个获取某一列内容的命令: ``` open Cargo.toml | get package # => ╭───────────────┬────────────────────────────────────╮ # => │ authors │ [list 1 item] │ # => │ default-run │ nu │ # => │ description │ A new type of shell │ # => │ documentation │ https://www.nushell.sh/book/ │ # => │ edition │ 2018 │ # => │ exclude │ [list 1 item] │ # => │ homepage │ https://www.nushell.sh │ # => │ license │ MIT │ # => │ metadata │ {record 1 field} │ # => │ name │ nu │ # => │ repository │ https://github.com/nushell/nushell │ # => │ rust-version │ 1.60 │ # => │ version │ 0.72.0 │ # => ╰───────────────┴────────────────────────────────────╯ ``` 如果需要,我们还可以进一步深入: ``` open Cargo.toml | get package.version # => 0.72.0 ``` ### 插件 Nu 支持提供额外功能的插件,这些插件遵循与内置命令相同的结构化数据模型。在 `crates/nu_plugins_*` 目录中有一些示例。 插件是位于你的 path 中的二进制文件,并遵循 `nu_plugin_*` 命名约定。 这些二进制文件通过简单的 JSON-RPC 协议与 nu 交互,命令在该协议中标识自身并传递其配置,使其可供使用。 如果插件是过滤器,数据会逐个元素地流向它,并且它可以通过 stdin/stdout 流式回传数据。 如果插件是接收器 (sink),它将获得完整的数据向量,并可以随意使用 stdin/stdout。 [awesome-nu repo](https://github.com/nushell/awesome-nu#plugins) 列出了各种 nu-plugins,而 [showcase repo](https://github.com/nushell/showcase) 则*展示*了关于 Nushell 的 informative 博客文章以及突显技术主题的视频。 ## 目标 Nu 紧密遵循一组构成其设计理念的目标。在添加功能时,会根据这些目标进行检查。 - 首先,Nu 是跨平台的。命令和技术应跨平台工作,Nu [为 Windows、macOS 和 Linux 提供一流支持](devdocs/PLATFORM_SUPPORT.md)。 - Nu 确保与现有的特定平台可执行文件的兼容性。 - Nu 的工作流程和工具应具备 2022 年(及以后)现代软件所预期的可用性。 - Nu 将数据视为结构化或非结构化。它像 PowerShell 一样是一个结构化 shell。 - 最后,Nu 以函数式的方式看待数据。管道不是使用变异,而是作为一种加载、更改和保存数据的方式,无需可变状态。 ## 官方支持 请提交 issue 或 PR 以添加到此列表。 - [zoxide](https://github.com/ajeetdsouza/zoxide) - [starship](https://github.com/starship/starship) - [oh-my-posh](https://ohmyposh.dev) - [Couchbase Shell](https://couchbase.sh) - [virtualenv](https://github.com/pypa/virtualenv) - [atuin](https://github.com/ellie/atuin) - [clap](https://github.com/clap-rs/clap/tree/master/clap_complete_nushell) - [Dorothy](http://github.com/bevry/dorothy) - [Direnv](https://github.com/direnv/direnv/blob/master/docs/hook.md#nushell) - [x-cmd](https://x-cmd.com/mod/nu) - [vfox](https://github.com/version-fox/vfox) - [Windmill](https://www.windmill.dev/docs/getting_started/scripts_quickstart/bash) ## 贡献 有关详细信息,请参阅 [Contributing](CONTRIBUTING.md)。感谢所有已经做出贡献的人! ## 许可证 本项目根据 MIT 许可证提供。有关更多信息,请参阅 `LICENSE` 文件。
标签:Awesome, CLI, Nushell, Rust, Shell, WiFi技术, ZAP项目解析, 可视化界面, 威胁情报, 开发者工具, 生产力工具, 管道, 系统管理, 终端, 网络流量审计, 网络调试, 脚本语言, 自动化, 调试插件, 通知系统, 通知系统