nushell / nushell/nushell

A command to remove indentations in multiline strings

Open
#11,477 16 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Related problem

Embedded code is written in multiline strings.

def main [name: string] {
    $'
    .($name)-class-1 {
        color: red;
    }

    .($name)-class-2 {
        color: blue;
    }
    ' | save $"($name).scss"
}

Once it's saved to a file (or, say, piped into an interpreter), indents persist, making code somewhat less readable. Not a problem if the created file is temporary, but it's something to be considered if the generated code is persistent and checked into the repo.


    .pkg2-class-1 {
        color: red;
    }

    .pkg2-class-2 {
        color: blue;
    }

    .pkg2-class-3 {
        color: green;
    }

    .pkg2-class-4 {
        color: aquamarine;
    }
    

Same goes for CSV and so on.

This is not good for scripts that write code to a file, which is frequent on a CI.

Describe the solution you'd like

A way (possibly a str unindent subcommand) to remove the indentation, similar to Kotlin's trimIndent.

Describe alternatives you've considered

Do not indent the code. This makes code less readable IMO, especially if there's multi level nesting (all nu code's on the right, and embedded code is suddenly all to the left).

def main [name: string] {
$'
.($name)-class-1 {
    color: red;
}

.($name)-class-2 {
    color: blue;
}

.($name)-class-3 {
    color: green;
}

.($name)-class-4 {
    color: aquamarine;
}
' | save $"($name).scss"
}
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

No files or tests are named in the issue. Start by locating the existing string subcommands and their tests, then examine how multiline strings are represented and piped. Done means a documented command removes common indentation from examples like the embedded CSS, with tests covering blank lines and varying indentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.