A CLI + macOS Text Services tool that tidies bash, perl and json code
blocks in any text editor on macOS — from the shell, or via the Services menu
in whatever app you're writing in.
It was built for Typora, which has no plugin API on macOS (conf.user.json
and the community typora_plugin project are Windows/Linux only) — so the
editor integration is built out of macOS Services instead, the extension
point the Mac app does offer. Since Services are a system-wide mechanism, the
same tidy-a-selection workflow works in any app that supports them, not just
Typora.
Formatters: shfmt, perltidy, jq.
Either clone and run the installer:
git clone <this-repo> ~/repos/mdtidy && cd ~/repos/mdtidy && ./install.shor copy a tarball over:
make dist # on this Mac -> dist/mdtidy-1.0.0.tar.gz
scp dist/mdtidy-1.0.0.tar.gz othermac: # then, on the other Mac:
tar xzf mdtidy-1.0.0.tar.gz && cd mdtidy-1.0.0 && ./install.shinstall.sh is idempotent — re-run it to upgrade. It will:
brew installany ofshfmt,perltidy,jqthat are missing (--no-depsto skip)- install
mdtidyandmdtidy-clipinto~/.local/bin - install
config.json,perltidyrcand the docs into~/.config/mdtidy, never overwriting an existing config (yours is kept, the new one lands as*.new) - generate the five
.workflowbundles in~/Library/Servicesand register them withpbs(--no-servicesto skip) - warn if
~/.local/binis missing fromPATH(--add-pathto append it to~/.zshrc) - smoke-test a bash, perl and json block end to end
Flags: --shortcuts also binds the default keystrokes — ⌥⇧⌘T (auto), ⌥⇧⌘B
(bash), ⌥⇧⌘P (perl), ⌥⇧⌘J (json) and ⌥⇧⌘M (tidy the whole file) — skipping any
combo already claimed by another service. Requires only python3 (system python3
is fine) and zsh.
The Service bundles are generated on each machine rather than shipped, so
Gatekeeper never quarantines them — that is why there are no .workflow
directories in this repo.
./uninstall.sh # binaries, services, shortcuts; keeps ~/.config/mdtidy
./uninstall.sh --purge # config tooshfmt, perltidy and jq are left installed either way.
bin/mdtidy the tool (python3, no third-party deps)
bin/mdtidy-clip tidy the clipboard in place
config/config.json fence tag -> formatter map, and formatter argv
config/perltidyrc perl style, passed with -pro=
services/install-services.py generates the macOS Services
scripts/set-shortcuts.sh bind/unbind the Services keyboard shortcuts (--show, --remove)
tests/run.sh golden-file + idempotence + sniffing tests
docs-usage.md day-to-day usage (installed as ~/.config/mdtidy/README.md)
make test # golden file, idempotence, language sniffing
make install # install from the working tree
make dist # tarballEdit bin/mdtidy (not ~/.local/bin/mdtidy), then make install. After
changing the shell script embedded in the Services, re-run
python3 services/install-services.py.
Usage, style customisation and the Typora workflow: docs-usage.md.
Beerware — do what you want with it; buy me a beer if we meet and you find it useful.