Shfmt silently eats changes in the buffer that have not been written to the file.
Steps to Reproduce:
Create a new file vim shfmt-test.bash
Put initial contents into the file, and write it with :w
#!/usr/bin/env bash
# Reproducce vim-shfmt issue
for bacon in "turkey" "pig"; do
echo $bacon | grep -q "pig" &&
echo "$bacon bacon is real bacon" ||
echo "$bacon bacon is not real bacon"
done
Run :Shfmt, get the properly reformatted script
#!/usr/bin/env bash
# Reproducce vim-shfmt issue
for bacon in "turkey" "pig"; do
echo $bacon | grep -q "pig" &&
echo "$bacon bacon is real bacon" ||
echo "$bacon bacon is not real bacon"
done
Make some more edits, but do not write them to the file
#!/usr/bin/env bash
# Reproducce vim-shfmt issue
for bacon in "turkey" "pig"; do
echo $bacon | grep -q "pig" &&
echo "$bacon bacon is real bacon" ||
echo "$bacon bacon is not real bacon"
done
echo "really important info that I forgot to add:"
echo "bacon goes really well on pizza"
4. Run `:Shfmt` and watch the unwritten edits disappear
```bash
#!/usr/bin/env bash
# Reproducce vim-shfmt issue
for bacon in "turkey" "pig"; do
echo $bacon | grep -q "pig" &&
echo "$bacon bacon is real bacon" ||
echo "$bacon bacon is not real bacon"
done
Environment:
macOS 10.14.2
vim 8.1 (from Homebrew)
vim-shfmt from commit 5f1fe6a with .vimrc options:
vim-shfmt is indeed running against the last saved file instead of running as a filter. I've submitted a pull request with changes to have it run as a filter instead.
Shfmt silently eats changes in the buffer that have not been written to the file.
Steps to Reproduce:
vim shfmt-test.bash
:w
:Shfmt
, get the properly reformatted scriptecho "really important info that I forgot to add:" echo "bacon goes really well on pizza"
Environment: macOS 10.14.2 vim 8.1 (from Homebrew) vim-shfmt from commit 5f1fe6a with .vimrc options: