Skip to content

Instantly share code, notes, and snippets.

@mikeplus64
Last active March 1, 2019 07:25
Show Gist options
  • Save mikeplus64/3bf4d6dfa3412e5485dceb71686c0630 to your computer and use it in GitHub Desktop.
Save mikeplus64/3bf4d6dfa3412e5485dceb71686c0630 to your computer and use it in GitHub Desktop.
apply stylish-haskell to only module preamble+imports, if stylish-haskell fails on entire module first
#!/usr/bin/env bash
INPUT="$(cat)"
IFS=''
ERRORS="$(mktemp)"
EXIT_OK=true
if ! (echo "$INPUT" | stylish-haskell 2>>"$ERRORS") ; then
PREAMBLE="$(echo "$INPUT" | grep -B100000 '^import')"
LEFTOVERS="$(echo "$INPUT" | tail -n +$((1 + $(echo "$PREAMBLE" | wc -l))))"
if echo "$PREAMBLE" | stylish-haskell 2>>"$ERRORS"; then
echo "$LEFTOVERS"
else
cat "$ERRORS" 1>&2
EXIT_OK=false
fi
fi
rm "$ERRORS"
$EXIT_OK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment