Skip to content

Instantly share code, notes, and snippets.

@hanggrian
Last active February 18, 2023 08:32
Show Gist options
  • Save hanggrian/19ea76cdf920431e5c43064e4d6db6c9 to your computer and use it in GitHub Desktop.
Save hanggrian/19ea76cdf920431e5c43064e4d6db6c9 to your computer and use it in GitHub Desktop.
Check files recursively
#!/bin/bash
# List final newline of all text files in a directory recursively.
readonly END=
readonly BOLD=
readonly RED=
readonly GREEN=
readonly YELLOW=
if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
echo "Usage: ${GREEN}check_final_newline.sh$END $YELLOW<directory>$END"
exit 0
fi
find "$1" -type d | while read dir; do
found="false"
echo
echo "$BOLD$dir:$END"
for file in "$dir/"*; do
if [[ -d "$file" ]]; then
continue
fi
found="true"
filename="$(basename -- "$file")" # remove path
if [[ "$(tail -c 1 "$file")" == "" ]]; then
status=${GREEN}Yes$END
else
status=${RED}No$END
fi
echo "- $filename: $status"
done
if [[ "$found" = false ]]; then
echo "${RED}Not found.$END"
fi
done
echo
echo "Goodbye!"
#!/bin/bash
# List bits per channel of all PNG files in a directory recursively.
readonly END=
readonly BOLD=
readonly RED=
readonly GREEN=
readonly YELLOW=
if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
echo "Usage: ${GREEN}check_png_bits.sh$END $YELLOW<directory>$END"
exit 0
fi
if ! command -v pngcheck &> /dev/null; then
echo "${RED}pngcheck is not installed.$END"
exit 1
fi
find "$1" -type d | while read dir; do
found="false"
echo
echo "$BOLD$dir:$END"
for file in "$dir/"*; do
if [[ "$file" =~ \.png$ ]]; then
found="true"
filename="$(basename -- "$file")" # remove path
filename="${filename%.*}" # remove extension
status="$(pngcheck "$file")"
status="$(echo "$status" | sed -E "s/-bit.*//")" # substring before last `-bit`
status="$(echo "$status" | rev | cut -d " " -f 1 | rev)" # substring after last ` `
echo "- $filename: $GREEN$status-bit$END"
fi
done
if [[ "$found" = false ]]; then
echo "${RED}Not found.$END"
fi
done
echo
echo "Goodbye!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment