3 -description: "Nushell shell and scripting — structured pipelines, current syntax, config, modules, redirection, errors, and Bash-to-Nu translation. Use when editing .nu files or converting shell snippets."
3 +description: "Use when writing, debugging, or modernizing Nu code/config, editing .nu files, or translating shell commands to Nushell. Not generic Bash or terminal work."
9 -Target the installed Nu, not this file. Nu changes quickly.
9 +Target installed Nu, not remembered syntax.
10 +Keep language guidance here; use `mise` for Mise integration
11 +and `linux-userland` for Linux HOME/XDG boundaries.
13 -Use local structured help first:
15 +Use `nu --no-config-file -c '<probe>'` for isolated language checks.
16 +This skips startup config, not inherited env or side effects in the probe.
17 +Never dump `$env`, source secret files,
18 +or run real login startup merely to check syntax.
16 -version | get version
21 +version | select version experimental_options
17 22 help commands | where name == "path type" | get input_output
18 -help commands | where name =~ "^str " | select name usage
19 23 help --find semver | select name usage
23 -If behavior is version-specific, check official release notes after local help:
26 -https://www.nushell.sh/blog/
27 -https://www.nushell.sh/book/
30 -Recent changelog check performed while refactoring: 0.114.0, 0.113.1, 0.113.0, 0.112.2. Result: keep current-feature details out of this skill; point to `help`/release notes instead.
34 -- Pipelines pass values: strings, records, lists, tables; not shell text lines.
35 -- Env vars live in `$env`: `$env.PATH`, `$env.LAST_EXIT_CODE`, `$env.config`.
36 -- Optional record/env fields use `?`: `$env.PWD?`, `$row.name?`.
37 -- `null` is `nothing`; path/file commands often reject it. Guard before calling.
38 -- External commands use `^cmd`; pass spread args as `^cmd ...$args`.
39 -- `help commands` is data; prefer filtering it over scraping docs.
41 -##
Bash → Nu instincts 43 -- `$VAR` → `$env.VAR`
44 -- `export A=b` → `$env.A = "b"`
45 -- `$?` → `$env.LAST_EXIT_CODE`
47 -- `cat file` → `open --raw file`
48 -- `grep x` on text → `lines | where $it =~ "x"`
49 -- `find . -name '*.nu'` → `ls **/*.nu`
50 -- `[ -f file ]` → `("file" | path type) == file`
51 -- `basename "$p"` → `$p | path basename`
52 -- `2>&1` for external commands → `o+e>|`
54 -No shell `&&`/`||`. Use `;` for sequencing, `and`/`or` for booleans, or inspect `$env.LAST_EXIT_CODE`.
58 -`which` returns a table of records, not a string. Extract the `path` field before passing it to external commands:
27 +For deprecated syntax, inspect command metadata when available:
61 -let pi_path = (which pi | get 0.path)
30 +scope commands | where name == "str upcase" | get deprecation_info
33 +For migrations, follow [Modernize](references/modernize.md):
34 +local help, intervening release notes, then isolated behavior checks.
35 +Do not copy website examples without checking the installed CLI.
39 +- Pipelines carry typed values; external programs exchange byte streams.
40 +- Use `$env.NAME` for environment variables and `$row.field?` for optional fields.
41 + `null` has type `nothing`; guard before passing optional paths to filesystem commands.
42 +- `which` returns records, possibly none;
43 + check emptiness before extracting `get 0.path`.
44 +- Use `^cmd` to bypass internal commands; pass argument lists as `^cmd ...$args`.
45 +- Use `and`/`or` for booleans, not `&&`/`||`.
46 + `;` sequences expressions, not conditional success;
47 + external failures can stop execution.
48 +- Use `save` for pipeline values, `o+e> file` for external output to a file,
49 + and `o+e>| filter` for combined output into a pipeline.
50 + Do not put a filename after `o+e>|`.
54 +Capture output and status together instead of assuming
55 +`$env.LAST_EXIT_CODE` behaves like Bash `$?` in every context:
68 -let q = [$p] | compact | first
69 -let t = if $q == null { null } else { try { $q | path type } catch { null } }
58 +let result = (^tool ...$args | complete)
59 +if $result.exit_code != 0 {
60 + error make {msg: $"tool exited ($result.exit_code)"}
62 +let data = try { $result.stdout | from json --strict } catch {
63 + error make {msg: "tool returned invalid JSON"}
72 -Redirection applies to external commands, not Nu internals:
67 +Use `from json --strict` when the external contract requires JSON;
68 +the default parser accepts non-JSON input too.
69 +Distinguish process failure, malformed data, and valid empty results.
70 +Do not replace failures with `null`, `[]`, or success
71 +unless the caller explicitly permits that fallback.
72 +Do not expose raw stderr or output that may contain secrets.
75 -"hello" | save out.txt
76 -"hello" | save --append out.txt
79 -try { internal-command } catch {|err| $err.msg }
74 +##
Config and scripts 76 +1. Identify the actual shell and launch mode:
77 + command string, script, interactive, or login.
78 + Use `$nu | columns`, then inspect only needed config paths,
79 + including `loginshell-path`, `vendor-autoload-dirs`, and `user-autoload-dirs`.
80 +2. Trace loaded files and their generators before editing activation warnings.
81 + Fix the owner or confirmed duplicate; do not patch generated output blindly.
82 +3. `source`, `use`, `run`, and `nu script.nu` are not interchangeable.
83 + Check local help for scope, pipeline input, `main` arguments,
84 + and top-level execution before switching invocation.
85 +4. Treat `$ans` as REPL state, not a script result store.
86 + Check local help before using version-specific argument annotations such as `external_arg`.
87 +5. Preserve typed signatures and error paths;
88 + reproduce type failures before blaming a release
89 + or disabling experimental checks.
93 +Read the target and its imports first; diagnostics may expose source literals.
94 +For reviewed, non-secret code, run the helper from this skill directory:
97 +node scripts/check.mjs /absolute/path/to/file.nu
100 +It runs `nu --no-config-file --ide-check 100`, reports Nu version and diagnostics,
101 +and fails on Error severity even when Nu exits zero.
102 +It does not run the script body; parsing can read imports and evaluate constants,
103 +so this is not a sandbox.
104 +Missing Nu, process failure, stderr, or malformed diagnostics fail closed.
105 +Warnings are reported when emitted, but a pass does not prove absence
106 +of deprecations; Nu 0.115.1 IDE mode omits some.
84 -Before giving version-sensitive Nu syntax, run a tiny `nu -c` probe when harmless:
108 +Then exercise positive and negative behavior with reviewed code
109 +in isolated temporary fixtures.
110 +Check exit codes, data shape, empty/missing inputs, and intended startup mode separately.
111 +Never execute a mutating script just to validate it.
87 -nu -c 'version | get version'
88 -nu -c 'help commands | where name == "path type" | length'
89 -nu -c '(which nu | get 0.path) | path type'
113 +Helper regression tests: `npm test` in this skill directory;
114 +requires Node and Nu on PATH.