Skip to content

Instantly share code, notes, and snippets.

@mnutt
Last active January 22, 2018 19:23
Show Gist options
  • Save mnutt/c34f03030d282eea11be0b0a5a5cc21e to your computer and use it in GitHub Desktop.
Save mnutt/c34f03030d282eea11be0b0a5a5cc21e to your computer and use it in GitHub Desktop.
Only run prettier if a config file is present
#!/bin/bash
# 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`
# try to see if there is a project-specific `prettier` to use
node_modules=`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