File Type: sh
Generated Description:
This bash script, organize.sh
, automates the organization of GitHub repositories into categorized directories based on configurable patterns. It aims to improve the structure and accessibility of a user's local GitHub repository collection.
The script takes a list of GitHub repositories (either from a user-provided file or by automatically discovering directories in a base directory) and moves or renames them into predefined categories. These categories are defined by regular expression patterns matching repository names and corresponding target directories. The script provides logging, progress updates, and a final report. It handles potential errors gracefully and offers a mechanism for automatically generating and updating the repository list file.
- Configuration: The script uses a configuration system based on files (
repositories.txt
,categories.conf
) for flexibility. Default configurations are also included. Environment variables can override some settings. load_repositories()
: This function is crucial. It loads the list of repositories either from a configuration file or by discovering them within the base directory usingfind
. If discovered, it automatically creates or updates the configuration file. This handles both user-specified and automatic repository discovery.get_destination_dir()
: This function takes a repository name as input and determines the appropriate destination directory based on the configured category patterns. It uses regular expression matching to classify repositories.main()
: The main function orchestrates the entire process: loading repositories, determining destination directories, moving or renaming repositories, and generating logs and reports.- Progress Tracking: The script incorporates functions (
init_progress
,update_progress
,complete_progress
) for displaying a progress bar during the repository processing, enhancing user experience. - Logging and Reporting: Detailed logs are written to a log file, including timestamps, processed repositories, and any errors encountered. A markdown report file is also generated.
- Error Handling: The
set -euo pipefail
shell options enable strict error checking, improving the robustness of the script. - Colorized Output: The script uses ANSI escape codes to colorize the output to the terminal for better visual feedback.
- Configuration Files: Use of configuration files allows for easy customization and reusability.
- Regular Expressions: Regular expressions are used for pattern matching in repository names to categorize them.
find
command: Efficiently discovers repositories within a directory.- Null-terminated output (
-print0
) withfind
: Handles repository names with spaces correctly. - Bash Arrays and Associative Arrays: Used effectively to store and access repository information and category mappings.
- Progress Bar: Improves user experience during potentially long-running operations.
- Modular Design: The script is broken into functions, making it more readable and maintainable.
- Robust Error Handling: The use of
set -euo pipefail
ensures that the script handles errors effectively and provides informative messages. - Automatic Repository List Generation: The script can discover and add new repositories to the configuration file, reducing the manual effort required for maintenance.
- Organizing a large number of GitHub repositories: Consolidates and categorizes many repositories, improving organization and findability.
- Maintaining consistent directory structure: Enforces a structured approach to local repository management.
- Automated repository backups: Can be integrated into a larger backup script to ensure that repositories are categorized correctly during backups.
- Setting up a new development environment: Helps quickly organize repositories during the setup of a new workstation.
- Streamlining project management: Improves the efficiency of finding and managing related repositories.
The script's configurable nature and automatic discovery features make it a versatile tool for managing a diverse collection of GitHub repositories.
Description generated on 3/29/2025, 5:45:57 AM