Created
April 20, 2023 16:37
-
-
Save Mario-SO/c988b26e4c4f6e24228bac6d5591d940 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env zsh | |
# Made by @mariodev__ | |
clear | |
# Check if the directory is provided | |
if [ -z "$1" ]; then | |
echo "Usage: $0 <directory>" | |
exit 1 | |
fi | |
# Check if the directory exists | |
if [ ! -d "$1" ]; then | |
echo "Error: Directory \"$1\" does not exist." | |
exit 1 | |
fi | |
# ANSI escape codes for colors | |
HEADER_COLOR="\033[1;34m" # Bold blue | |
DATA_COLOR="\033[1;32m" # Bold green | |
LINE_COLOR="\033[1;31m" # Bold red | |
RESET_COLOR="\033[0m" # Reset to default color | |
# Create a temporary file to store filenames, line numbers, and descriptions | |
temp_file=$(mktemp) | |
# Loop through the files in the directory | |
for file in "$1"/*; do | |
if [ -f "$file" ]; then | |
file_name=$(basename "$file") | |
grep -n "// @audit -" "$file" | awk -F: -v file="$file_name" '{split($0, a, "// @audit -"); printf "%-40s %13s %s\n", file, $1, a[2] }' >> "$temp_file" | |
fi | |
done | |
# Function to draw a horizontal line | |
draw_horizontal_line() { | |
printf "${LINE_COLOR}+%-40s+%-13s+%-50s+${RESET_COLOR}\n" "$(printf '%0.1s' -{1..40})" "$(printf '%0.1s' -{1..13})" "$(printf '%0.1s' -{1..50})" | |
} | |
# Header of the table | |
draw_horizontal_line | |
printf "${HEADER_COLOR}${LINE_COLOR}|${RESET_COLOR}${HEADER_COLOR}%-40s${RESET_COLOR}${LINE_COLOR}|${RESET_COLOR}${HEADER_COLOR}%13s${RESET_COLOR}${LINE_COLOR}|${RESET_COLOR}${HEADER_COLOR}%-50s${RESET_COLOR}${LINE_COLOR}|${RESET_COLOR}\n" " Filename" "Line Number " " Audit Description" | |
draw_horizontal_line | |
# Print the result from the temporary file | |
while read -r line; do | |
file_name=$(echo "$line" | awk '{ print $1 }') | |
line_number=$(echo "$line" | awk '{ print $2 }') | |
description=$(echo "$line" | awk '{$1=$2=""; print substr($0, 3)}') | |
if [ ! -z "$description" ]; then | |
printf "${LINE_COLOR}|${RESET_COLOR}${DATA_COLOR}%-40s${RESET_COLOR}${LINE_COLOR}|${RESET_COLOR}${DATA_COLOR}%13s${RESET_COLOR}${LINE_COLOR}|${RESET_COLOR}${DATA_COLOR}%-50s${RESET_COLOR}${LINE_COLOR}|${RESET_COLOR}\n" " $file_name" "$line_number " " $description" | |
fi | |
done < "$temp_file" | |
# Footer of the table | |
draw_horizontal_line | |
# Remove the temporary file | |
rm "$temp_file" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment