Skip to content

Instantly share code, notes, and snippets.

@ActuallyFro
Created September 24, 2024 02:24
Show Gist options
  • Select an option

  • Save ActuallyFro/a553ea612fdc93832de0cc38ebbc0a4a to your computer and use it in GitHub Desktop.

Select an option

Save ActuallyFro/a553ea612fdc93832de0cc38ebbc0a4a to your computer and use it in GitHub Desktop.
I take notes, I want where/when and how much to be reported.
#!/bin/bash
# Main script logic
directory="$1" # Directory passed as an argument, or use the current directory if none is provided
if [[ -z "$directory" ]]; then
directory="."
fi
# Check if the directory exists
if [[ ! -d "$directory" ]]; then
echo "ERROR: The specified directory '$directory' does not exist."
exit 1
fi
# Create an array to hold results
results=()
# Get the current year
current_year=$(date +"%Y")
# Loop through each top-level folder (ignoring deeper subfolders)
while IFS= read -r top_folder; do
# Count all .md files in the current top-level folder and its subfolders
total_md_files=$(find "$top_folder" -type f -name "*.md" | wc -l)
# Get the date and folder name using ls -ld
folder_info=$(ls -ld "$top_folder")
# Check for timestamp and extract the date
if echo "$folder_info" | grep -q ':'; then
# Timestamp present, set year to current year
current_date=$(echo "$folder_info" | awk -v year="$current_year" '{print $6, $7, year}') # Format: Mmm DD YYYY
else
# No timestamp, extract original date
current_date=$(echo "$folder_info" | awk '{print $6, $7, $8}') # Format: Mmm DD YYYY
fi
# Extract the day for padding
day=$(echo "$current_date" | awk '{print $2}')
# Pad the date if the day is a single digit
if [[ ${#day} -eq 1 ]]; then
current_date="$current_date " # Add space after year for single digit day
fi
folder_name=$(basename "$top_folder")
# Prepare the output line
results+=("$current_date $folder_name (Note files: $total_md_files)")
done < <(find "$directory" -maxdepth 1 -mindepth 1 -type d | sort)
# Print the sorted results
printf "%s\n" "${results[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment