Home > OS >  Making a dynamic bash-command that pipelins git status-paths into a "dip"-command
Making a dynamic bash-command that pipelins git status-paths into a "dip"-command

Time:12-13

I'm working on a project that uses dip, where a code-sniffer has been implemented.

If I change two files and create a new file, so git status --porcelain gives me this:

 M path/to/my/file/comments.php
 M path/to/my/file/footer.php
 D path/to/my/file/some-deleted-file.php
?? path/to/my/file/test.php

Then I would like to run a one-liner, bash command that passes those three files (that is not deleted) into the command, like this:

dip sniff fix path/to/my/file/comments.php path/to/my/file/footer.php path/to/my/file/test.php

I'm looking for a bash one-liner bash-command that achieves.

Ideally, it would be relative paths (unlike what git status --porcelain returns), so I could run the magical command I'm looking for, from any subfolder of the project.

Solution attempt 1: git status | awk | tr | dip

I think I'm close with this command here:

git status --porcelain | awk -F' ' '{ print $2 }' | tr '\n' ' ' | dip sniff fix

But that throws this error: the input device is not a TTY. It happens the second that dip tries to start up the docker container. Maybe there is a timing-issue... Hmm.

This command here: git status --porcelain | awk -F' ' '{ print $2 }' | tr '\n' ' ' returns this:

path/to/my/file/comments.php path/to/my/file/footer.php path/to/my/file/test.php

I also tried adding a bunch of flags to the dip-command found here (dip sniff fix -i and dip sniff fix -it, etc.).

And besides, that doesn't account for deleted files.

Update based on Ed Mortons comments

It's a good idea to get the tr out of it, to simplify.

So now I do this (but I still get an error, whenever it reaches the dip-command):

$ git status --porcelain | awk '{printf "%s%s", sep, $2; sep=OFS} END{print ""}' | dip sniff fix

# RESULT:
the input device is not a TTY

CodePudding user response:

I don't know anything about dip, but this looks like it can't read from a pipeline. You can try the following:

dip sniff fix $(git status --porcelain | awk '{printf "%s%s", sep, $2; sep=OFS} END{print ""}')
  • Related