Skip to content

Commit

Permalink
Add support for relative files and rebasing
Browse files Browse the repository at this point in the history
  • Loading branch information
palas committed Jul 17, 2024
1 parent d4c08cf commit f70763b
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions scripts/devshell/prettify
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit f70763b

Please sign in to comment.