Home > OS >  Use powershell to run a command for changed files in git
Use powershell to run a command for changed files in git

Time:09-14

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?

CodePudding user response:

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 ';')
  • Related