Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for relative files and rebasing #842

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading