<< All versions
Skill v1.0.1
Automated scan100/100majiayu000/claude-skill-registry/nushell
3 files
──Details
PublishedMay 15, 2026 at 07:21 AM
Content Hashsha256:27d109471eee875f...
Git SHA4a67e6f2e6a1
Bump Typepatch
──Files
Files (1 file, 13.0 KB)
SKILL.md13.0 KBactive
SKILL.md · 889 lines · 13.0 KB
version: "1.0.1" name: nushell description: Guide for using Nushell for structured data pipelines and scripting. Use when writing shell scripts, processing structured data, or working with cross-platform automation.
Nushell - Modern Structured Shell
This skill activates when working with Nushell (Nu), writing Nu scripts, working with structured data pipelines, or configuring the Nu environment.
When to Use This Skill
Activate when:
- Writing Nushell scripts or commands
- Working with structured data in pipelines
- Converting from bash/zsh to Nushell
- Configuring Nushell environment
- Processing JSON, CSV, YAML, or other structured data
- Creating custom commands or modules
What is Nushell?
Nushell is a modern shell that:
- Treats data as structured (not just text streams)
- Works cross-platform (Windows, macOS, Linux)
- Provides clear error messages and IDE support
- Combines shell and programming language features
- Has built-in data format support (JSON, CSV, YAML, TOML, XML, etc.)
Installation
bash
# macOSbrew install nushell# Linux (cargo)cargo install nu# Windowswinget install nushell# Or download from https://www.nushell.sh/
Basic Concepts
Everything is Data
Unlike traditional shells where everything is text, Nu works with structured data:
nu
# Traditional shell (text output)ls | grep ".txt"# Nushell (structured data)ls | where name =~ ".txt"
Pipeline Philosophy
Data flows through pipelines as structured tables/records:
nu
# Each command outputs structured datals | where size > 1kb | sort-by modified | reverse
Data Types
Basic Types
nu
# Integers42-10# Floats3.14-2.5# Strings"hello"'world'# Booleanstruefalse# Nullnull
Collections
nu
# Lists[1 2 3 4 5]["apple" "banana" "cherry"]# Records (like objects/dicts){name: "Alice", age: 30, city: "NYC"}# Tables (list of records)[{name: "Alice", age: 30}{name: "Bob", age: 25}]
Ranges
nu
# Number ranges1..101..2..10 # Step by 2# Use in commands1..5 | each { |i| $i * 2 }
Working with Files and Directories
Navigation
nu
# Change directorycd /path/to/dir# List files (returns structured table)ls# List with detailsls | select name size modified# Filter filesls | where type == filels | where size > 1mbls | where name =~ "\.txt$"
File Operations
nu
# Create file"hello" | save hello.txt# Read fileopen hello.txt# Append to file"world" | save -a hello.txt# Copycp source.txt dest.txt# Move/renamemv old.txt new.txt# Removerm file.txtrm -r directory/# Create directorymkdir new-dir
File Content
nu
# Read as stringopen file.txt# Read structured dataopen data.jsonopen config.tomlopen data.csv# Write structured data{name: "Alice", age: 30} | to json | save user.json[{a: 1} {a: 2}] | to csv | save data.csv
Pipeline Operations
Filtering
nu
# Filter with wherels | where size > 1mbls | where type == dirls | where name =~ "test"# Multiple conditionsls | where size > 1kb and type == file
Selecting Columns
nu
# Select specific columnsls | select name size# Rename columnsls | select name size | rename file bytes
Sorting
nu
# Sort by columnls | sort-by sizels | sort-by modified# Reverse sortls | sort-by size | reverse# Multiple columnsls | sort-by type size
Transforming Data
nu
# Map over items with each1..5 | each { |i| $i * 2 }# Update columnls | update name { |row| $row.name | str upcase }# Insert columnls | insert size_kb { |row| $row.size / 1000 }# Upsert (update or insert)ls | upsert type_upper { |row| $row.type | str upcase }
Aggregation
nu
# Count itemsls | length# Sum[1 2 3 4 5] | math sum# Average[1 2 3 4 5] | math avg# Min/Maxls | get size | math maxls | get size | math min# Group byls | group-by type
Variables
Variable Assignment
nu
# Let (immutable by default)let name = "Alice"let age = 30let colors = ["red" "green" "blue"]# Mut (mutable)mut counter = 0$counter = $counter + 1
Using Variables
nu
# Reference with $let name = "Alice"print $"Hello, ($name)!"# In pipelineslet threshold = 1mbls | where size > $threshold
Environment Variables
nu
# Get environment variable$env.PATH$env.HOME# Set environment variable$env.MY_VAR = "value"# Load from fileload-env { API_KEY: "secret" }
String Operations
String Interpolation
nu
# String interpolation with ()let name = "Alice"print $"Hello, ($name)!"# With expressionslet x = 5print $"Result: (5 * $x)"
String Methods
nu
# Case conversion"hello" | str upcase # HELLO"WORLD" | str downcase # world# Trimming" spaces " | str trim# Replace"hello world" | str replace "world" "nu"# Contains"hello world" | str contains "world" # true# Split"a,b,c" | split row ","
Conditionals
If Expressions
nu
# If-elseif $age >= 18 {print "Adult"} else {print "Minor"}# If-else if-elseif $score >= 90 {"A"} else if $score >= 80 {"B"} else {"C"}# Ternary-style with matchlet status = if $is_active { "active" } else { "inactive" }
Match (Pattern Matching)
nu
# Match expressionmatch $value {1 => "one"2 => "two"_ => "other"}# With conditionsmatch $age {0..17 => "minor"18..64 => "adult"_ => "senior"}
Loops
For Loop
nu
# Loop over rangefor i in 1..5 {print $i}# Loop over listfor name in ["Alice" "Bob" "Charlie"] {print $"Hello, ($name)"}# Loop over filesfor file in (ls | where type == file) {print $file.name}
While Loop
nu
# While loopmut i = 0while $i < 5 {print $i$i = $i + 1}
Each (Functional)
nu
# Transform each item1..5 | each { |i| $i * 2 }# With index["a" "b" "c"] | enumerate | each { |item|print $"($item.index): ($item.item)"}
Custom Commands
Defining Commands
nu
# Simple commanddef greet [name: string] {print $"Hello, ($name)!"}greet "Alice"# With return valuedef add [a: int, b: int] {$a + $b}let result = add 5 3# With default valuesdef greet [name: string = "World"] {print $"Hello, ($name)!"}
Command Parameters
nu
# Required parametersdef copy [source: path, dest: path] {cp $source $dest}# Optional parametersdef greet [name: string--loud (-l) # Flag--repeat (-r): int = 1 # Named parameter with default] {let message = if $loud {$name | str upcase} else {$name}1..$repeat | each { print $"Hello, ($message)!" }}# Usagegreet "Alice"greet "Bob" --loudgreet "Charlie" --repeat 3
Pipeline Commands
nu
# Accept pipeline inputdef filter-large [] {where size > 1mb}# Usagels | filter-large# Accept and transform pipelinedef double [] {each { |value| $value * 2 }}[1 2 3] | double
Working with Structured Data
JSON
nu
# Read JSONlet data = open data.json# Parse JSON stringlet obj = '{"name": "Alice", "age": 30}' | from json# Write JSON{name: "Alice", age: 30} | to json | save user.json# Pretty print JSON{name: "Alice", age: 30} | to json -i 2
CSV
nu
# Read CSVlet data = open data.csv# Convert to CSV[{a: 1, b: 2} {a: 3, b: 4}] | to csv# Save CSVls | select name size | to csv | save files.csv
YAML/TOML
nu
# Read YAMLlet config = open config.yaml# Read TOMLlet config = open config.toml# Write YAML{key: "value"} | to yaml | save config.yaml# Write TOML{key: "value"} | to toml | save config.toml
Working with Tables
nu
# Create tablelet users = [{name: "Alice", age: 30, city: "NYC"}{name: "Bob", age: 25, city: "LA"}{name: "Charlie", age: 35, city: "NYC"}]# Query table$users | where age > 25$users | where city == "NYC"$users | select name age# Add column$users | insert country { "USA" }# Group and count$users | group-by city | transpose city users
Modules
Creating Modules
nu
# utils.nuexport def greet [name: string] {print $"Hello, ($name)!"}export def add [a: int, b: int] {$a + $b}
Using Modules
nu
# Import moduleuse utils.nu# Use exported commandsutils greet "Alice"utils add 5 3# Import specific commandsuse utils.nu [greet add]greet "Alice"add 5 3# Import with aliasuse utils.nu *
Configuration
Config File Location
nu
# View configconfig nu# Edit configconfig nu | open# Config location$nu.config-path
Common Configurations
nu
# config.nu$env.config = {show_banner: falsels: {use_ls_colors: trueclickable_links: true}table: {mode: roundedindex_mode: auto}completions: {quick: truepartial: true}history: {max_size: 10000sync_on_enter: truefile_format: "sqlite"}}
Environment Setup
nu
# env.nu$env.PATH = ($env.PATH | split row (char esep) | append '/custom/bin')$env.EDITOR = "nvim"# Load completionsuse completions/git.nu *
Common Patterns
File Processing
nu
# Process all JSON filesls *.json | each { |file|let data = open $file.nameprint $"Processing ($file.name): ($data | length) items"}# Batch rename filesls *.txt | each { |file|let new_name = ($file.name | str replace ".txt" ".md")mv $file.name $new_name}
Data Transformation
nu
# CSV to JSONopen data.csv | to json | save data.json# Filter and transformopen users.json| where active == true| select name email| to csv| save active_users.csv# Merge datalet users = open users.jsonlet orders = open orders.json$users | merge $orders
HTTP Requests
nu
# GET requesthttp get https://api.example.com/users# POST requesthttp post https://api.example.com/users {name: "Alice"email: "alice@example.com"}# With headershttp get -H [Authorization "Bearer token"] https://api.example.com/data
System Commands
nu
# Run external command^ls -la# Capture outputlet output = (^git status)# Check if command existswhich git# Get command pathwhich git | get path
Error Handling
Try-Catch
nu
# Try expressiontry {open missing.txt} catch {print "File not found"}# With error valuetry {open missing.txt} catch { |err|print $"Error: ($err)"}
Null Handling
nu
# Default valuelet value = ($env.MY_VAR? | default "default_value")# Null propagationlet length = ($value | get name? | str length)
Scripting
Script Files
nu
#!/usr/bin/env nu# Script: process_logs.nu# Description: Process log files and generate reportdef main [log_dir: path] {let errors = (ls $"($log_dir)/*.log"| each { |file| open $file.name | lines }| flatten| where $it =~ "ERROR")print $"Found ($errors | length) errors"$errors | save error_report.txt}
Make executable:
bash
chmod +x process_logs.nu./process_logs.nu /var/log
Script Parameters
nu
# With parametersdef main [input: path--output (-o): path = "output.txt"--verbose (-v)] {if $verbose {print $"Processing ($input)..."}let data = open $input$data | save $outputif $verbose {print "Done!"}}
Comparison with Bash
Common Operations
bash
# Bashfind . -name "*.txt" | wc -l# Nushellls **/*.txt | length
bash
# Bashcat file.json | jq '.users[] | select(.age > 25) | .name'# Nushellopen file.json | get users | where age > 25 | get name
bash
# Bashfor file in *.txt; domv "$file" "${file%.txt}.md"done# Nushellls *.txt | each { |f| mv $f.name ($f.name | str replace ".txt" ".md") }
Best Practices
- Use structured data: Leverage Nu's strength in handling structured data
- Pipeline composition: Build complex operations from simple pipeline stages
- Type annotations: Add types to custom command parameters for clarity
- Error handling: Use try-catch for operations that might fail
- Modules for reuse: Organize reusable commands in modules
- Configuration: Customize Nu to fit your workflow
- External commands: Use
^prefix when calling external commands explicitly
Common Pitfalls
String vs Bare Words
nu
# Bare word (interpreted as string in some contexts)echo hello# Explicit string (clearer)echo "hello"
External Commands
nu
# Wrong - Nu tries to parse as Nu commandls -la# Right - Explicitly call external command^ls -la
Variable Scope
nu
# Variables are scoped to blocksif true {let x = 5}# $x not available here# Use mut outside for wider scopemut x = 0if true {$x = 5}print $x # Works
Key Principles
- Structured data first: Think in terms of tables and records, not text
- Pipeline composition: Chain simple operations to build complex workflows
- Type safety: Leverage Nu's type system for reliable scripts
- Cross-platform: Write scripts that work on all platforms
- Interactive and scriptable: Same syntax works in REPL and scripts
- Clear errors: Nu provides helpful error messages for debugging