0

I'm not a very skilled linux user and I'm trying to make an automation for vscode such that I can open all the files with diff in them in vscode. My current suggestion is:

git diff master...[BRANCH_NAME] --name-only |code -r

The first part git diff master...[BRANCH_NAME] --name-only works perfectly fine giving:

src/components/LeftDrawerMenu/TaskForm/index.js
src/services/util.js

But the code -r does not registering the output as input. It runs as if there where no arguments.

I want the following:

code -r src/services/util.js src/components/LeftDrawerMenu/TaskForm/index.js

But

code -r src/services/util.js 
code -r src/components/LeftDrawerMenu/TaskForm/index.js 

would also give the desired outcome. What do I do wrong?

konsolebox
  • 72,135
  • 12
  • 99
  • 105
Peter Mølgaard Pallesen
  • 1,470
  • 1
  • 15
  • 26

1 Answers1

1

I'm afraid that a pipe for different lines of output might not be handled correctly. Did you already try this:

code -r $(git diff master...[BRANCH_NAME] --name-only)
Dominique
  • 16,450
  • 15
  • 56
  • 112
  • 1
    _grumble_. Not that this doesn't work in the simple case, but unquoted command substitution has a bunch of generally-unwanted behaviors (glob expansion, word-splitting on IFS); better to read into an array with `readarray -t myarray < <(...)`, `mapfile-t myarray < <(...)` or `IFS=$'\n' read -r -d '' -a myarray < <(... && printf '\0')` and then expand that array. – Charles Duffy Jan 04 '22 at 14:28
  • Even better would be `git diff master...BRANCH_NAME --name-only | xargs -d $'\n' code -r`, which works right (by splitting into multiple `code` invocations) even when the list of names is too long to fit on a single command line. – Charles Duffy Jan 04 '22 at 14:31