Skip to content

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mdtidy

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.

Install on another Mac

Either clone and run the installer:

git clone <this-repo> ~/repos/mdtidy && cd ~/repos/mdtidy && ./install.sh

or 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.sh

install.sh is idempotent — re-run it to upgrade. It will:

  1. brew install any of shfmt, perltidy, jq that are missing (--no-deps to skip)
  2. install mdtidy and mdtidy-clip into ~/.local/bin
  3. install config.json, perltidyrc and the docs into ~/.config/mdtidy, never overwriting an existing config (yours is kept, the new one lands as *.new)
  4. generate the five .workflow bundles in ~/Library/Services and register them with pbs (--no-services to skip)
  5. warn if ~/.local/bin is missing from PATH (--add-path to append it to ~/.zshrc)
  6. 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

./uninstall.sh            # binaries, services, shortcuts; keeps ~/.config/mdtidy
./uninstall.sh --purge    # config too

shfmt, perltidy and jq are left installed either way.

Layout

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)

Development

make test       # golden file, idempotence, language sniffing
make install    # install from the working tree
make dist       # tarball

Edit 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.

License

Beerware — do what you want with it; buy me a beer if we meet and you find it useful.

About

A CLI + macOS Text Services tool that tidies bash/perl/json code blocks in any text editor on macOS.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages