Repository navigation
How to add shell command with pipe? #44
Description
Activity
@chrisgrieser can you take a look at #49 and see if it works for you? You can run the command in a shell by returning args as a string instead of a list. e.g.
args = "--format=diff $FILENAME | git apply"
thx, indeed the change works as it should, that is the using a string as
args.Only problem is, the related shell command does not play nice with temp files, it seems? 🤔
shellcheck foobar.sh --format=diff
--- a/foobar.sh +++ b/foobar.sh @@ -1,1 +1,1 @@ -echo $SHELL +echo "$SHELL"
Reading via stdin does not work here, since the diff is missing the filenames for
git apply:--- a/- +++ b/-
Reading the file directly apparently has the issue that the temp files apparently cause some issue, too. Here the error message from
:ConformInfo07:38:23[ERROR] Formatter 'shellcheck' error: shellcheck: shellcheck: openBinaryFile: does not exist (No such file or directory) error: zsh/Users/chrisgrieser/.config/zsh/.conform.6310933.foobar.sh: No such file or directoryfor reference, here is the config I am using:
shellcheck = { command = "shellcheck", args = "shellcheck $FILENAME --shell=bash --format=diff | git apply", stdin = false, },
In case this is not directly solvable, an alternative approach for this particular case might be for conform.nvim to use the diff resulting from
shellcheck --format=diffand apply the changes, since it has some diff-applying method anyway?In the linked issue they mention using
| patch -p1. Does that approach work better thangit apply? Anything that relies on git is going to have problems with temp files.hmm, using
| patch -p1also does not seem to work11:40:15[INFO] Run shellcheck on /Users/chrisgrieser/.config/zsh/foobar.sh 11:40:15[DEBUG] Creating temp file /Users/chrisgrieser/.config/zsh/.conform.6310933.foobar.sh 11:40:15[DEBUG] Run command: shellcheck shellcheck /Users/chrisgrieser/.config/zsh/.conform.6310933.foobar.sh --shell=bash --format=diff | patch -p1 11:40:15[INFO] shellcheck exited with code 1 11:40:15[DEBUG] shellcheck stdout: nil 11:40:15[DEBUG] shellcheck stderr: { "shellcheck: shellcheck: openBinaryFile: does not exist (No such file or directory)", "" } 11:40:15[DEBUG] Cleaning up temp file /Users/chrisgrieser/.config/zsh/.conform.6310933.foobar.sh 11:40:15[ERROR] Formatter 'shellcheck' error: shellcheck: shellcheck: openBinaryFile: does not exist (No such file or directory)Try this definition:
formatters = { shellcheck = { command = "shellcheck", args = "$FILENAME --shell=bash --format=diff | patch -p1 $FILENAME", stdin = false, }, },
nice, that one works! Thx for the support. 🥳
Guess that one can also be directly be added to the conform.nvim, I guess? (when #49 is merged)
Reacted by Steven Arcangeli
The way conform.nvim is set up, it seems slightly more complicated commands do not work.
For example,
shellcheckcan be used to auto-fix some issues using this, effectively replacingshellharden:shellcheck --format=diff my_file.sh | git applyThis works fine in the terminal, but the following config does not work:
I assume this is because in the background, conform.nvim uses
fn.systemwith a list of strings, where pipes do not work. However, usingfn.systemwith a single string does work fine, but passing a string toargsresults in an error.Is there a way to make this work?