1

I want to use jb cleanupcode --include .\file1;.\file2 to only format code that has changed. I.e. I want to run git diff --name-only and then feed the output to the jb cleanupcode command using its --include flag.

The issue is that git diff --name-only produces a list of files one-per-line.

Question: how do I take a stream of path-per-file and turn it into a semicolon-separated list fed to a command?

1 Answer 1

2

Use the -join operator to join the resulting paths together:

$names = @(git diff --name-only) -join ';'
jb cleanupcode --include $names

Or as a single statement:

jb cleanupcode --include (@(git diff --name-only) -join ';')
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you! Is there a way to make it a one-liner using pipes?
@THX-1138 piping data makes little sense since you need to pass all names to jb up front - but I've updated the answer to show how you can combine the statements

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.