Call For Testing: shfmt



shfmt is a command line program - A shell parser, formatter and interpreter (POSIX/Bash/mksh). This tool can be called directly on the command line or added to some editors (such as vscode with an extension like

NOTE - Currently this snap is in strict confinement with the home plug. So obviously your code needs to be in your home directory. Open to suggestions if there are improvements for this (i.e. - to account for those who do not store their code in their home directory) without requesting classic confinement.

EDIT - ok, the vscode stuff needs to hold up for the moment. I just realized there are access issues going from the snap to a snap. Likely need another plug (suggestions in case I don’t find the answer right away?)

How to install

sudo snap install shfmt

Requested Setups

Since this is a go binary, there are no external dependencies. I would say at a minimum, test at the terminal. If so inclined, a test within vscode would not hurt.

Vscode setup

  • install vscode if you do not have it already with sudo snap install vscode --classic
  • Install the vscode shell-format extension with code --install-extension
  • Open your vscode settings.json and add "shellformat.path": "/snap/bin/shfmt". Keep in mind that you would need a comma at the end if you are not adding this at the end of your config.

Specific tests

  • Run against a shell script (with an intentional error) at the terminal with shfmt -l -w
  • Open the same bad script in vscode and ensure the same errors appear in the lower left corner.

Test result

  • If running against a proper shell script, it should return with a blank line.
  • If running aginst a bad shell script, it should return an error with the results such as:
$ shfmt -l -w if statement must end with "fi"

Output of “snap version”

$ snap version
snap    2.35.4
snapd   2.35.4
series  16
ubuntu  18.04
kernel  4.15.0-38-generic

Output of “dmesg” when application is launched, which can be useful when debugging confinement issues.

vscode shfmt dmesg errors

[ 2908.781603] audit: type=1400 audit(1540537254.332:540): apparmor="DENIED" operation="file_inherit" profile="/snap/core/5662/usr/lib/snapd/snap-confine" pid=9870 comm="snap-confine" family="unix" sock_type="stream" protocol=0 requested_mask="send receive" denied_mask="send receive" addr=none peer_addr=none


I’m going to try and work on this tomorrow. This is the biggest roadblock with it right now.


You can declare the removable-media interface connection to allow access of scripts under /media and /run/media (and /mnt in the near future)


It shouldn’t be a problem if the vscode snap is in classic confinement (likely it is) as it can access all host commands including those provided by the snap


@bashfulrobot Dustin, thank you for creating a snap for shfmt.

Submitted a PR to add it to the project’s README -


I saw that! Thanks for doing that. I just pushed the V2.6.2 into the edge channel. I’m slowly trying to get the author to see how low impact the build can be and long term I hope he will take over. Right now he wants to leave it to the “Community”. Maybe over time if the snap package gets a decent set of users, I can shovel some metrics over to him. I would love to get it hooked up to his git repo at some point. But I had the same issue with the Restic snap. I use that one so much though that I don’t mind maintaining for now (but also would like to get it up-streamed). Or at least to the point where I can get the authors to wire them into their repos (and even if I triage the snap related issues)