Skip to content

Instantly share code, notes, and snippets.

@mnutt
Created June 6, 2019 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mnutt/45f7a494876a0ce391edf31915fcf571 to your computer and use it in GitHub Desktop.
Save mnutt/45f7a494876a0ce391edf31915fcf571 to your computer and use it in GitHub Desktop.
Prettier project wrapper
#!/bin/bash
# This wrapper prefers your project's prettier version, and only runs prettier if your project has configured it.
# Save this file as `prettier` in your $PATH, or set your editor's prettier plugin to use it as the prettier binary
# find the file prettier is trying to prettify
file=${BASH_ARGV[0]:="."}
# optionally set where the real prettier command can be found
prettier=`which prettier`
node_modules=`/usr/local/bin/npm root`
if [ -f "${node_modules}/.bin/prettier" ]; then
prettier="$node_modules/.bin/prettier"
fi
if $prettier --find-config-path ${file} > /dev/null; then
exec $prettier "$@"
else
exec cat <&0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment