diff --git a/scripts/devshell/prettify b/scripts/devshell/prettify index e18b0d8eee..60db957899 100755 --- a/scripts/devshell/prettify +++ b/scripts/devshell/prettify @@ -6,24 +6,26 @@ show_help() { echo "Format Haskell source files using fourmolu and stylish-haskell." echo "" echo "Options:" - echo " -t, --tracked Format all tracked Haskell (*.hs) files in the repository" - echo " -s, --staged Format all staged Haskell (*.hs) files" - echo " -m, --modified Format all modified Haskell (*.hs) files, including staged and unstaged" - echo " -n, --not-staged Format all non-staged modified Haskell (*.hs) files" - echo " -h, --help Show this help message" + echo " -t, --tracked Format all tracked Haskell (*.hs) files in the repository" + echo " -s, --staged Format all staged Haskell (*.hs) files" + echo " -m, --modified Format all modified Haskell (*.hs) files, including staged and unstaged" + echo " -n, --not-staged Format all non-staged modified Haskell (*.hs) files" + echo " -p, --previous-commit Format all Haskell (*.hs) files modified before the last commit (HEAD~1)" + echo " -h, --help Show this help message" } # Function to run the formatting commands run_format() { + top_level=$(git rev-parse --show-toplevel) for file in "$@"; do if [[ $file == *.hs ]]; then - if grep -qE '^#' "$file"; then + if grep -qE '^#' "$top_level/$file"; then echo "$file contains CPP. Skipping." else echo "Formatting: $file" - fourmolu -q -i "$file" - fourmolu -q -i "$file" - stylish-haskell -i "$file" + fourmolu -q -i "$top_level/$file" + fourmolu -q -i "$top_level/$file" + stylish-haskell -i "$top_level/$file" fi fi done @@ -45,6 +47,9 @@ case $1 in -n|--not-staged) files=$(git diff --name-only --diff-filter=ACM '*.hs') ;; + -p|--previous-commit) + files=$(git diff --name-only --diff-filter=ACM HEAD~1 '*.hs') + ;; -h|--help) show_help exit 0