Skip to content

Instantly share code, notes, and snippets.

@chussenot
Created September 19, 2023 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chussenot/487c187756fa5d6ab8bd4b2b48eceebe to your computer and use it in GitHub Desktop.
Save chussenot/487c187756fa5d6ab8bd4b2b48eceebe to your computer and use it in GitHub Desktop.
Simple script to sort repos by the last commits
#!/bin/bash
folder_path="adeo"
cd "$folder_path" || exit 1
# Function to get the last commit date of a repository (directory)
get_last_commit_date() {
local directory="$1"
cd "$directory" || return 1
last_commit_date=$(git log -1 --format="%ci")
echo "$last_commit_date"
}
# Associative array to store directory and its last commit date
declare -A directory_commit_dates
# Loop through all directories and get their last commit date
for directory in */; do
directory=${directory%/} # Remove trailing slash from directory name
if [ -d "$directory/.git" ]; then
last_commit_date=$(get_last_commit_date "$directory")
directory_commit_dates["$directory"]=$last_commit_date
fi
done
# Sort directories by last commit date in descending order
sorted_directories=$(for dir in "${!directory_commit_dates[@]}"; do
echo "${directory_commit_dates[$dir]} $dir"
done | sort -r | cut -d' ' -f2-)
# Print sorted directory names only
echo "Directories ordered by last commit date (freshness):"
for dir in $sorted_directories; do
echo "$dir" | sed -n '1p'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment