emeraldwalk / vscode-runonsave

Visual Studio Code extension to run commands whenever a file is saved.
Apache License 2.0
182 stars 57 forks source link

WSL2: Writing piped STDOUT to same file doesn't work #32

Closed pankgeorg closed 4 years ago

pankgeorg commented 5 years ago

This doesn't work (Pipe to file)

"emeraldwalk.runonsave": {
        "commands": [
            {
                "match": ".sql",
                "cmd": "cat ${file} | ~/sqlfmt --print-width 88 --tab-width 2 --use-spaces --no-simplify > ${file}"
            }
        ]
    }

This is a workaround:

"emeraldwalk.runonsave": {
        "commands": [
            {
                "match": ".sql",
                "cmd": "cat ${file} | ~/sqlfmt --print-width 88 --tab-width 2 --use-spaces --no-simplify > ${file}2; mv ${file}2 ${file}"
            }
        ]
    }

Any ideas?

bmingles commented 5 years ago

Does that command work outside of the extension? I'd be surprised if you can pipe back into the file you are piping out of.

e.g. Creating a file test.txt with some content and running

cat test.txt > test.txt

wipes out the file contents instead of writing to it.

bmingles commented 4 years ago

This doesn't appear to be an issue with the extension but an issue with piping data back into the same file that it is being piped from.