nushell / nushell/nushell

Mutable "pipeline assignment" operator

Open
#14,870 5 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A:syntax category:enhancement status:needs-triage
Dominant language
Rust
Stars
40.5k
Forks
2.3k
Avg merge
1d 14h
Merged PRs (30d)
79

Description

Related problem

I'm not sure if I have the naming right, but when dealing with config (or other mutable variables), the convenience of the += and ++= operators only goes so far. When dealing with, for instance, a record that needs a merge, you still have to resort to $variable = $variable | merge {}.

We currently have:

╭───┬──────────┬────────────────╮
│ # │ operator │      name      │
├───┼──────────┼────────────────┤
│ 0 │ +=       │ PlusAssign     │
│ 1 │ ++=      │ ConcatAssign   │
│ 2 │ -=       │ MinusAssign    │
│ 3 │ *=       │ MultiplyAssign │
│ 4 │ /=       │ DivideAssign   │
╰───┴──────────┴────────────────╯
Describe the solution you'd like

A PipeAssign operator, probably |= which would allow a RHS expression that would simply use the value of the LHS as pipeline input. For example:

mut foo = "foo"
$foo |= str upcase
$foo
# => FOO

This comes in handy with longer $env.config entries.

# Without operator:
$env.config.hooks.env_change = (
    $env.config.hooks.env_change
    | merge deep --strategy=append {
          PWD: [{|before,after| null }]
      }
)

# With operator
$env.config.hooks.env_change |= merge deep --strategy=append {
    PWD: [{|before,after| null }]
}
Describe alternatives you've considered

No response

Additional context and details

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files, tests, or entry points. Begin by tracing the existing += and ++= assignment operators in the Nushell source, then establish the scope and acceptance cases for |= from the examples, including mutable variables and nested $env.config paths.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, shell
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.