2024-07-31 06:22:18 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-07-31 06:23:31 +02:00
|
|
|
output_file=~/workshop/repos.txt
|
2024-07-31 06:22:18 +02:00
|
|
|
|
2024-07-31 06:23:31 +02:00
|
|
|
# Ensure the output directory exists
|
|
|
|
mkdir -p "$(dirname "$output_file")"
|
2024-07-31 06:22:18 +02:00
|
|
|
|
2024-07-31 06:23:31 +02:00
|
|
|
# Clear the existing file
|
|
|
|
> "$output_file"
|
2024-07-31 06:22:18 +02:00
|
|
|
|
2024-07-31 06:23:31 +02:00
|
|
|
# Find all .git directories, excluding hidden directories and suppressing permission denied errors
|
|
|
|
find ~/ -type d -name ".git" -not -path "*/.*/*" 2>/dev/null | while read -r gitdir; do
|
|
|
|
# Get the parent directory of the .git folder
|
|
|
|
repo_path=$(dirname "$gitdir")
|
|
|
|
echo "$repo_path" >> "$output_file"
|
|
|
|
done
|
2024-07-31 06:22:18 +02:00
|
|
|
|
2024-07-31 06:23:31 +02:00
|
|
|
echo "Git repositories have been written to $output_file"
|
2024-07-31 06:22:18 +02:00
|
|
|
|
2024-07-31 06:23:31 +02:00
|
|
|
# Remove duplicate entries
|
|
|
|
sort -u "$output_file" -o "$output_file"
|
2024-07-31 06:22:18 +02:00
|
|
|
|
2024-07-31 06:23:31 +02:00
|
|
|
echo "Duplicate entries removed. Final list:"
|
|
|
|
cat "$output_file"
|
2024-07-31 06:22:18 +02:00
|
|
|
|