# nutest **Repository Path**: graviton/nutest ## Basic Information - **Project Name**: nutest - **Description**: nushell test - **Primary Language**: Unknown - **License**: LGPL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-05-06 - **Last Updated**: 2026-04-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 🐚 Nushell 学习项目 一个基于 [Nushell 官方中文文档](https://www.nushell.sh/zh-CN/book/) 的交互式学习项目,通过可运行的代码 Demo 帮助理解 Nushell 的核心概念和常用命令。 ## 📋 前置要求 - [Nushell](https://www.nushell.sh/) >= 0.107.0 验证安装: ```nushell nu --version ``` ## 🚀 快速开始 ```nushell # 1. 列出所有可用 Demo nu main.nu list # 2. 运行全部 Demo nu main.nu run_all # 3. 交互式运行单个主题 nu main.nu # 或直接 source 后调用 source main.nu quick_tour run_all types_of_data demo_basic_types ``` ## 📂 项目结构 ``` . ├── main.nu # 项目入口,统一导入所有 Demo ├── myprt.nu # 公共工具(prtH 标题打印等) ├── te1.nu # 原有测试模块(兼容保留) ├── demos/ # 主题 Demo 目录 │ ├── quick_tour.nu # 快速上手 │ ├── moving_around.nu # 文件浏览与目录导航 │ ├── thinking_in_nu.nu # Nushell 思维方式 │ ├── cheat_sheet.nu # 常用命令速查表 │ ├── types_of_data.nu # 数据类型(int、list、record、table...) │ ├── loading_data.nu # 加载与保存数据(JSON/CSV/TOML) │ ├── pipelines.nu # 管道与数据处理 │ ├── working_with_strings.nu # 字符串操作 │ ├── working_with_lists.nu # 列表操作 │ ├── working_with_records.nu # 记录(record)操作 │ ├── working_with_tables.nu # 表格(table)操作 │ ├── navigating_structured_data.nu # 嵌套结构化数据导航 │ └── special_variables.nu # 特殊变量($nu、$in、$env...) └── README.md ``` ## 📚 Demo 主题说明 | 文件 | 对应文档 | 内容 | | ------------------------------- | ----------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | | `quick_tour.nu` | [quick_tour](https://www.nushell.sh/zh-CN/book/quick_tour.html) | 基本命令、结构化输出、管道、变量 | | `moving_around.nu` | [moving_around](https://www.nushell.sh/zh-CN/book/moving_around.html) | ls、cd、open、特殊路径、目录栈 | | `thinking_in_nu.nu` | [thinking_in_nu](https://www.nushell.sh/zh-CN/book/thinking_in_nu.html) | 编译型 Shell、不可变性、错误处理、数据思维 | | `cheat_sheet.nu` | [cheat_sheet](https://www.nushell.sh/zh-CN/book/cheat_sheet.html) | 常用命令、查询命令、字符串、数学统计速查 | | `types_of_data.nu` | [types_of_data](https://www.nushell.sh/zh-CN/book/types_of_data.html) | int、float、string、bool、filesize、duration、list、record、table、closure | | `loading_data.nu` | [loading_data](https://www.nushell.sh/zh-CN/book/loading_data.html) | open、save、JSON/CSV/TOML 读写、HTTP 请求 | | `pipelines.nu` | [pipelines](https://www.nushell.sh/zh-CN/book/pipelines.html) | \$in 变量、多行管道、条件管道、错误处理、flatten | | `working_with_strings.nu` | [working_with_strings](https://www.nushell.sh/zh-CN/book/working_with_strings.html) | 插值、join、trim、replace、split、base64、正则 | | `working_with_lists.nu` | [working_with_lists](https://www.nushell.sh/zh-CN/book/working_with_lists.html) | each、where、find、sort、flatten、reduce、prepend/append | | `working_with_records.nu` | [working_with_records](https://www.nushell.sh/zh-CN/book/working_with_records.html) | insert/update/upsert/reject、merge、items、transpose | | `working_with_tables.nu` | [working_with_tables](https://www.nushell.sh/zh-CN/book/working_with_tables.html) | select/get、where、sort-by、group-by、join、rename | | `navigating_structured_data.nu` | [navigating_structured_data](https://www.nushell.sh/zh-CN/book/navigating_structured_data.html) | 嵌套数据访问、深层 get、flatten、转置、实际 API 场景 | | `special_variables.nu` | [special_variables](https://www.nushell.sh/zh-CN/book/special_variables.html) | \$nu、\$in、\$env、\$nothing、scope 命令 | ## 🎯 使用示例 ### 运行单个主题的全部 Demo ```nushell source main.nu working_with_tables run_all ``` ### 运行具体的子 Demo ```nushell source main.nu loading_data demo_load_json special_variables demo_env_variable working_with_strings demo_regex ``` ### 运行原有测试 ```nushell source main.nu te1_1 tt te1_2.run_all ``` ## 🛠 扩展项目 在 `demos/` 目录下新建 `.nu` 文件,遵循以下约定即可被 `main.nu` 自动识别和调用: 1. 每个 Demo 文件是一个 Nushell 模块 2. 导出多个以 `demo_` 为前缀的函数,每个聚焦一个知识点 3. 导出一个 `run_all` 函数,按顺序调用所有 `demo_` 函数 4. 使用 `use ../myprt.nu *` 导入 `prtH` 用于打印分隔标题 示例模板: ```nushell use ../myprt.nu * export def demo_my_topic [] { prtH "My Topic - 子标题" # 你的示例代码 print "Hello Nushell" } export def run_all [] { demo_my_topic } ``` 然后在 `main.nu` 中添加: ```nushell use demos/my_topic.nu ``` 并在 `run_all` 和 `list` 中注册即可。 ## 📖 参考资料 - [Nushell 官方文档(中文)](https://www.nushell.sh/zh-CN/book/) - [Nushell GitHub](https://github.com/nushell/nushell) ## 📄 许可证 [LICENSE](./LICENSE)