nushell-fundamentals
This skill should be used when the user asks to "write a Nushell script", "create a Nushell command", "understand Nushell syntax", "work with Nushell pipelines", "use closures in Nushell", "create a Nushell module", "define an overlay", "understand Nushell types", or mentions core Nushell concepts like pipelines, closures, modules, overlays, custom commands, or type annotations.
What this skill does
# Nushell Fundamentals
Comprehensive reference for core Nushell language patterns, syntax, and best practices. Nushell treats data as structured tables rather than text streams, enabling type-safe pipelines and powerful data manipulation.
## Core Philosophy
Nushell follows the Unix philosophy with modern enhancements:
- **Everything is data** - Commands return structured tables, records, and lists
- **Pipelines are typed** - Data flows with known shapes between commands
- **Errors are values** - Explicit error handling, not silent failures
- **Help is built-in** - Every command has discoverable documentation
## Data Types
### Primitive Types
| Type | Example | Description |
|------|---------|-------------|
| `int` | `42`, `-17` | 64-bit signed integers |
| `float` | `3.14`, `1e-5` | 64-bit floating point |
| `string` | `"hello"`, `'world'` | UTF-8 text |
| `bool` | `true`, `false` | Boolean values |
| `duration` | `5min`, `2hr`, `1day` | Time durations |
| `filesize` | `10kb`, `1gb`, `512mb` | File sizes |
| `date` | `2024-01-15` | Date/datetime |
| `nothing` | `null` | Absence of value |
| `binary` | `0x[FF 00 AB]` | Raw bytes |
### Structured Types
| Type | Syntax | Description |
|------|--------|-------------|
| `list` | `[1, 2, 3]` | Ordered collection |
| `record` | `{name: "foo", value: 42}` | Key-value mapping |
| `table` | `[[a, b]; [1, 2], [3, 4]]` | List of records |
| `closure` | `{\|x\| $x + 1}` | Anonymous function |
### Type Annotations
Annotate function parameters and return types for safety:
```nushell
def greet [name: string] -> string {
$"Hello, ($name)!"
}
def add [a: int, b: int] -> int {
$a + $b
}
# Optional parameters with defaults
def connect [host: string, --port: int = 8080] {
# ...
}
# Rest parameters
def sum [...nums: int] -> int {
$nums | math sum
}
```
## Pipelines
### Basic Pipeline Flow
```nushell
# Data flows left to right through pipes
ls | where size > 1mb | sort-by modified | first 5
# Each stage receives the output of the previous
open data.json | get users | where active == true
```
### Pipeline Input/Output
Commands declare their pipeline signature:
- **Input type** - What data the command accepts
- **Output type** - What data the command produces
```nushell
# nothing -> table<name, size, modified>
ls
# table -> table (filters rows)
where size > 1mb
# any -> any (transforms each element)
each { |it| $it.name | str upcase }
```
### Spreading into Pipelines
Use spread operator for multiple values:
```nushell
[...[1, 2], ...[3, 4]] # [1, 2, 3, 4]
{...{a: 1}, ...{b: 2}} # {a: 1, b: 2}
```
## Custom Commands
### Basic Definition
```nushell
# Simple command
def hello [] {
"Hello, World!"
}
# With typed parameters
def greet [name: string] {
print $"Hello, ($name)!"
}
```
### Flags and Options
```nushell
def fetch-data [
url: string # Required positional
--format: string # Optional flag with value
--verbose (-v) # Boolean flag with short form
--timeout: duration = 30sec # Flag with default
] {
# Implementation
}
# Usage: fetch-data https://api.example.com --format json -v
```
### Documentation
```nushell
# Fetch data from a URL
#
# Returns the response body parsed according to format.
#
# Examples:
# fetch-data https://api.example.com
# fetch-data https://api.example.com --format json --verbose
def fetch-data [
url: string # The URL to fetch
--format: string # Response format (json, text, binary)
--verbose (-v) # Enable verbose output
] -> any {
# Implementation
}
```
## Closures
### Syntax
```nushell
# Explicit parameter
let double = {|x| $x * 2}
# Using $in for implicit input
let double = { $in * 2 }
# Multiple parameters
let add = {|a, b| $a + $b}
```
### Common Uses
```nushell
# Iteration
[1, 2, 3] | each { |n| $n * 2 }
# Filtering
ls | where { |f| $f.size > 1mb }
# Reduction
[1, 2, 3, 4] | reduce { |acc, x| $acc + $x }
# Transformation
{name: "test", value: 42} | update value { |r| $r.value * 2 }
```
## Modules
### Creating a Module
```nushell
# math-utils.nu
export def double [n: int] -> int {
$n * 2
}
export def square [n: int] -> int {
$n * $n
}
# Private (not exported)
def helper [] {
# Internal use only
}
```
### Using Modules
```nushell
# Import entire module
use math-utils.nu
# Import specific commands
use math-utils.nu [double, square]
# Import with prefix
use math-utils.nu *
```
### Module Constants
```nushell
# config.nu
export const VERSION = "1.0.0"
export const API_URL = "https://api.example.com"
```
## Overlays
Overlays provide scoped environments that can be added/removed:
```nushell
# Create overlay from module
overlay use ./my-env.nu
# List active overlays
overlay list
# Remove overlay
overlay hide my-env
# Create named overlay
overlay new dev-env
# Add commands to current overlay
def my-cmd [] { "hello" }
```
### Overlay Use Cases
- **Development environments** - Different tool versions
- **Project-specific configs** - Custom commands per project
- **Feature flags** - Enable/disable functionality
## Control Flow
### Conditionals
```nushell
if $condition {
# true branch
} else if $other {
# else if branch
} else {
# false branch
}
# Match expressions
match $value {
"a" => "got a"
"b" | "c" => "got b or c"
$x if $x > 10 => "big number"
_ => "default"
}
```
### Loops
```nushell
# For loop
for item in [1, 2, 3] {
print $item
}
# While loop
mut counter = 0
while $counter < 10 {
$counter = $counter + 1
}
# Loop with break/continue
loop {
if $condition { break }
continue
}
```
### Error Handling
```nushell
# Try/catch
try {
risky-operation
} catch { |err|
print $"Error: ($err.msg)"
}
# Propagate errors
def safe-divide [a: int, b: int] -> int {
if $b == 0 {
error make { msg: "Division by zero" }
}
$a / $b
}
```
## Variables and Scope
### Immutable by Default
```nushell
let name = "value" # Immutable
mut counter = 0 # Mutable
const PI = 3.14159 # Compile-time constant
```
### Environment Variables
```nushell
$env.MY_VAR = "value" # Set
$env.MY_VAR # Read
$env.MY_VAR? # Read with null fallback
hide-env MY_VAR # Remove
```
### Scope Rules
```nushell
let outer = "outer"
do {
let inner = "inner" # Scoped to block
print $outer # Can access outer
}
# $inner not accessible here
```
## String Interpolation
```nushell
let name = "world"
$"Hello, ($name)!" # Interpolated string
$"Math: (2 + 2)" # Expressions work
$"Today: (date now | format date '%Y-%m-%d')" # Pipelines work
# Raw strings (no interpolation)
r#'Hello, ($name)!'# # Literal: Hello, ($name)!
```
## Help System
Access built-in documentation:
```nushell
help commands # List all commands
help modules # List modules
help operators # Operator reference
help escapes # Escape sequences
help pipe-and-redirect # Pipeline syntax
help ls # Specific command help
help str # Subcommand category
```
## Additional Resources
### Reference Files
For detailed patterns and advanced techniques:
- **`references/patterns.md`** - Idiomatic Nushell patterns
- **`references/configuration.md`** - Complete `$env.config` reference (from `config nu --doc`)
- **`references/type-system.md`** - Complete type system reference
- **`references/module-patterns.md`** - Module organization patterns
### Example Files
Working examples in `examples/`:
- **`basic-script.nu`** - Simple script template
- **`custom-command.nu`** - Command definition patterns
- **`module-example/`** - Complete module structure
### Scripts
Utility scripts in `scripts/`:
- **`validate-syntax.nu`** - Validate .nu file syntax
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.