Basic guide for organising project data

Full script for auto creation.

In your main “projects” folder (bonsai can be whatever you want):

nano bonsai
#!/bin/bash

# bonsai - Plant your project with care
# A simple project structure generator

set -e

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

print_status() {
    echo -e "${GREEN}==>${NC} $1"
}

print_warning() {
    echo -e "${YELLOW}Warning:${NC} $1"
}

print_error() {
    echo -e "${RED}Error:${NC} $1"
}

print_info() {
    echo -e "${BLUE}-->${NC} $1"
}

show_help() {
    cat << EOF
Usage: ./bonsai <project-name>

Example:
    ./bonsai project_zeus

Options:
    -h, --help    Show this help message
EOF
}

# Parse arguments
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
    show_help
    exit 0
fi

PROJECT_NAME="$1"

if [ -z "$PROJECT_NAME" ]; then
    print_error "No project name provided"
    show_help
    exit 1
fi

# Check if project directory exists
if [ -d "$PROJECT_NAME" ]; then
    print_error "Directory already exists: $PROJECT_NAME"
    exit 1
fi

# Ask about helper scripts
echo
echo "Would you like to include the helper scripts? (search, backup, mess list, validator) [y/N] "
read -r include_scripts

# Show what will be done
echo
print_info "The following actions will be performed:"
echo "  - Create directory: ./$PROJECT_NAME"
echo "  - Create subdirectories: AI, docs, images, mess, project/{logic,outline,phase1,phase2,phase3}"
echo "  - Create initial files: mess.txt, initial_prompt.txt, project_prompt.txt"

if [[ "$include_scripts" =~ ^[Yy]$ ]]; then
    echo "  - Add helper scripts:"
    echo "      ./$PROJECT_NAME/search"
    echo "      ./$PROJECT_NAME/mess/mess"
    echo "      ./$PROJECT_NAME/project/validate_v1.0"
    if [ -f "backup" ]; then
        echo "      ./backup (already exists - will be skipped)"
    else
        echo "      ./backup"
    fi
fi

echo
echo "Proceed? [y/N] "
read -r confirm

if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
    print_status "Cancelled."
    exit 0
fi

# Create structure
print_status "Creating folder structure..."
mkdir -p "$PROJECT_NAME"/{AI,docs,images,mess,project/{logic,outline,phase1,phase2,phase3}}

# Create initial files
touch "$PROJECT_NAME/mess/mess.txt"
touch "$PROJECT_NAME/AI/initial_prompt.txt"
touch "$PROJECT_NAME/AI/project_prompt.txt"

# Add helper scripts if requested
if [[ "$include_scripts" =~ ^[Yy]$ ]]; then
    print_status "Adding helper scripts..."
    
    # search script in project root
    cat > "$PROJECT_NAME/search" << 'EOF'
#!/bin/bash
# Usage: ./search <pattern>

if [ $# -eq 0 ]; then
    echo "Usage: ./search <pattern>"
    exit 1
fi

find . -name "*$1*" 2>/dev/null
EOF
    chmod +x "$PROJECT_NAME/search"
    print_info "Created $PROJECT_NAME/search"
    
    # mess list script
    cat > "$PROJECT_NAME/mess/mess" << 'EOF'
#!/bin/bash
# List current directory contents
ls -1 . > mess.txt
echo "Done."
EOF
    chmod +x "$PROJECT_NAME/mess/mess"
    print_info "Created $PROJECT_NAME/mess/mess"
    
    # validation script in project folder
    cat > "$PROJECT_NAME/project/validate_v1.0" << 'EOF'
#!/bin/bash

echo
echo "Unversioned files:"
echo "------------------"
find . -type f ! -name '*v[0-9]*.[0-9]*'
echo
echo "Done."
EOF
    chmod +x "$PROJECT_NAME/project/validate_v1.0"
    print_info "Created $PROJECT_NAME/project/validate_v1.0"
    
    # backup script in parent directory (same level as bonsai)
    if [ -f "backup" ]; then
        print_warning "backup script already exists, skipping..."
    else
        cat > "backup" << 'EOF'
#!/bin/bash
# Bonsai backup script - edit the destination before using
# Usage: ./backup <project-folder>

# Check if the project folder was specified:
if [ $# -eq 0 ]; then
    echo "Usage: ./backup <project-folder>"
    echo "Example: ./backup project_projectable"
    exit 1
fi

# The full string prepared for rsync:
PROJECT="$1"
DEST="niall@server:/home/niall/projects/"  # e.g., user@server:/home/user/projects/
TARGET="$DEST$PROJECT"

# Check if project folder exists:
if [ ! -d "$PROJECT" ]; then
    echo "Project folder not found: $PROJECT"
    exit 1
fi

# Check if destination has been set:
if [ -z "$DEST" ]; then
    echo "Please edit this script and set DEST first"
    exit 1
fi

# Confirm the operation:
echo
echo "Backing up to: $TARGET"
echo
echo "Confirm?"

read -r confirm
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
    echo "Cancelled."
    exit 0
fi

# Perform the operation using rsync.
rsync -azP "$PROJECT" "$TARGET"
echo "Done."
EOF
        chmod +x "backup"
        print_info "Created ./backup"
        print_warning "Don't forget to edit ./backup and set DEST if needed"
    fi
fi

print_status "Done. Project created at ./$PROJECT_NAME"

if [[ "$include_scripts" =~ ^[Yy]$ ]]; then
    echo
    echo "Helper scripts available:"
    echo "  ./$PROJECT_NAME/search                - Find files"
    echo "  ./$PROJECT_NAME/mess/mess             - Update mess list"
    echo "  ./$PROJECT_NAME/project/validate_v1.0 - Check versioning"
    echo "  ./backup                              - Backup (configure first)"
fi

exit 0

Then:

chmod +x bonsai

To run:

./bonsai project_name

To backup: Alter the DEST in the script, e.g. DEST="niall@server:/home/niall/projects/"

nano backup
./backup project_name

Suggestions welcome.

Syntax highlighting - #3 by niallm12