projecrt management////, you pipe in the name of your project, and it sets up subfolder, detects other projects, and gives you a std out of the folder struct, but also a output stream of all performed opperations

#!/bin/bash

# Define main directory and files for projects and operations log
PROJECTS_DIR="projects"
PROJECTS_LIST="$PROJECTS_DIR/projects_list.txt"
OPERATIONS_LOG="$PROJECTS_DIR/operations_log.txt"

# Color definitions
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

# Ensure the main projects directory and necessary files exist
mkdir -p "$PROJECTS_DIR"
touch "$PROJECTS_LIST"
touch "$OPERATIONS_LOG"

# Function to initialize a project with subfolders if it doesn't exist
initializeProject() {
    local projectName=$1
    local projectPath="$PROJECTS_DIR/$projectName"
    if [ ! -d "$projectPath" ]; then
        echo -e "${GREEN}Initializing '$projectName' for the first time...${NC}"
        mkdir -p "$projectPath"/{docs,team,code}
        touch "$projectPath/CONTRIBUTING.md"
        echo "$projectName" >> "$PROJECTS_LIST"
        echo "$(date): '$projectName' initialized" >> "$OPERATIONS_LOG"
        echo -e "\n${YELLOW}'$projectName' structure initialized: docs, team, code directories, and CONTRIBUTING.md${NC}\n"
    else
        echo -e "\n${RED}'$projectName' already exists.${NC}\n"
    fi
}

# Detect and add any new projects found in the main directory
detectAndAddProjects() {
    echo -e "${YELLOW}Detecting and adding new projects...${NC}"
    for projectPath in "$PROJECTS_DIR"/*; do
        if [ -d "$projectPath" ]; then
            local projectName=$(basename "$projectPath")
            if ! grep -Fxq "$projectName" "$PROJECTS_LIST"; then
                echo "$projectName" >> "$PROJECTS_LIST"
                echo "New project detected and added: $projectName"
            fi
        fi
    done
    echo -e "\n${GREEN}Detection complete.${NC}\n"
}

# Function to list the structure and details of all projects
listProjectsAndDetails() {
    echo -e "${YELLOW}Listing all projects and their structures:${NC}"
    while IFS= read -r projectName; do
        if [ -n "$projectName" ]; then
            local projectPath="$PROJECTS_DIR/$projectName"
            echo -e "${GREEN}- Project Name: $projectName${NC}"
            echo "  Subfolders:"
            for folder in docs team code; do
                if [ -d "$projectPath/$folder" ]; then
                    echo "    - $folder"
                fi
            done
            echo "  Recent Files:"
            local files=$(find "$projectPath" -maxdepth 1 -type f -printf "    - %f\n")
            if [ -z "$files" ]; then
                echo "    None"
            else
                echo "$files"
            fi
            echo
        fi
    done < "$PROJECTS_LIST"
    echo "Operations applied to all projects."
}

# Function to list all operations performed
listAllOperations() {
    echo -e "${YELLOW}Listing all operations performed on projects:${NC}"
    if [ -s "$OPERATIONS_LOG" ]; then
        cat "$OPERATIONS_LOG"
    else
        echo "No operations logged yet."
    fi
    echo -e "\n"
}

# Main execution logic
detectAndAddProjects

# Process stdin for project names
if [ ! -t 0 ]; then  # Data is being piped in
    while IFS= read -r projectName; do
        if [ -n "$projectName" ]; then
            initializeProject "$projectName"
        fi
    done
else
    echo -e "${RED}No project name piped in.${NC}\n"
fi

# After initialization or detection, list all projects' details
listProjectsAndDetails

# Finally, list all logged operations
listAllOperations

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *