Skip to content

Commit

Permalink
Fix using of absolute paths in prettify script
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed Aug 23, 2024
1 parent fe2ae13 commit 054f646
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions scripts/devshell/prettify
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,25 @@ show_help() {
echo " -h, --help Show this help message"
}

green_colour="\033[0;32m"
blue_colour="\033[0;34m"
orange_colour="\033[0;33m"
reset_colour="\033[0m"

# Function to run the formatting commands
run_format() {
top_level=$(git rev-parse --show-toplevel)
echo -e "${green_colour}Running in ${blue_colour}${top_level}${reset_colour}"
for file in "$@"; do
if [[ $file == *.hs ]]; then
if grep -qE '^#' "$top_level/$file"; then
echo "$file contains CPP. Skipping."
relative_path=$(realpath --relative-to="$top_level" "$file")
if grep -qE '^#' "$top_level/$relative_path"; then
echo -e "${orange_colour}${relative_path} contains CPP. Skipping.${reset_colour}"
else
echo "Formatting: $file"
fourmolu -q -i "$top_level/$file"
fourmolu -q -i "$top_level/$file"
stylish-haskell -i "$top_level/$file"
echo -e "${green_colour}Formatting: ${blue_colour}${relative_path}${reset_colour}"
fourmolu -q -i "$top_level/$relative_path"
fourmolu -q -i "$top_level/$relative_path"
stylish-haskell -i "$top_level/$relative_path"
fi
fi
done
Expand Down Expand Up @@ -71,16 +78,15 @@ for file in $files; do
if [[ ! -a $file ]]; then
echo "ERROR: $file does not exist"
exit 1
if ![[ -f $file ]]; then
echo "ERROR: $file is not a regular file"
exit
fi
elif ! [[ -f $file ]]; then
echo "ERROR: $file is not a regular file"
exit
fi
done

for tool in stylish-haskell fourmolu
do
if !(which $tool > /dev/null 2>&1); then
if ! (which $tool > /dev/null 2>&1); then
echo "ERROR: $tool is not available!"
echo -e
echo "Try entering the development shell with:"
Expand Down

0 comments on commit 054f646

Please sign in to comment.