Last active
February 18, 2023 08:32
-
-
Save hanggrian/19ea76cdf920431e5c43064e4d6db6c9 to your computer and use it in GitHub Desktop.
Check files recursively
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# List final newline of all text files in a directory recursively. | |
readonly END=[0m | |
readonly BOLD=[1m | |
readonly RED=[91m | |
readonly GREEN=[92m | |
readonly YELLOW=[93m | |
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!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# List bits per channel of all PNG files in a directory recursively. | |
readonly END=[0m | |
readonly BOLD=[1m | |
readonly RED=[91m | |
readonly GREEN=[92m | |
readonly YELLOW=[93m | |
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