Skip to content

Automatically split pipes and ForEach-Object commands to a new line #10572

@thomasrea0113

Description

@thomasrea0113

Summary of the new feature/enhancement

This is really just a continuation of the issue #3020, as it didn't really provide a satisfactory answer. As far as I can understand it, the #9614 PR doesn't really offer a solution for this scenario. I'd like to the ability to take the following line:

$Ports | ForEach-Object -Process { NETSTAT.EXE -ano | findstr.exe :8080 | ForEach-Object -Process { ($_ -split '\s+')[-1] } | Sort-Object | Get-Unique | ForEach-Object -Process { taskkill.exe /F /PID $_ } }

and convert it to:

$Ports |
    ForEach-Object -Process {
        NETSTAT.EXE -ano |
            findstr.exe :8080 |
            ForEach-Object -Process {
                ($_ -split '\s+')[-1]
            } | Sort-Object |
            Get-Unique |
            ForEach-Object -Process {
                taskkill.exe /F /PID $_
            }
    }

I think this would go a long way in approving readability. At the very least, with the

"powershell.codeFormatting.pipelineIndentationStyle": "IncreaseIndentationForFirstPipeline"

setting enabled, when I manually add the new line after each | and }, it will format the indentation correctly which is nice.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugResolution-AnsweredThe question is answered.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions