mirror of
https://github.com/acedanger/shell.git
synced 2025-12-06 01:10:12 -08:00
177 lines
6.0 KiB
Bash
Executable File
177 lines
6.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Cleanup script for removing my-aliases.zsh from git tracking
|
|
# This script handles the repository cleanup needed after the alias file
|
|
# was changed from tracked to dynamically generated
|
|
|
|
set -e
|
|
|
|
# Colors for output
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
RED='\033[0;31m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Script directory and repository root
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
REPO_ROOT="$SCRIPT_DIR"
|
|
|
|
echo -e "${BLUE}=== Alias File Tracking Cleanup Script ===${NC}"
|
|
echo -e "${YELLOW}This script will remove my-aliases.zsh from git tracking${NC}"
|
|
echo -e "${YELLOW}and update .gitignore to prevent future conflicts.${NC}"
|
|
echo ""
|
|
|
|
# Verify we're in a git repository
|
|
if [ ! -d "$REPO_ROOT/.git" ]; then
|
|
echo -e "${RED}Error: Not in a git repository${NC}"
|
|
echo "Please run this script from the root of your shell repository"
|
|
exit 1
|
|
fi
|
|
|
|
# Change to repository root
|
|
cd "$REPO_ROOT"
|
|
|
|
# Check current git status
|
|
echo -e "${BLUE}=== Current Git Status ===${NC}"
|
|
git status --porcelain
|
|
|
|
# Check if my-aliases.zsh is currently tracked
|
|
if git ls-files --error-unmatch dotfiles/my-aliases.zsh >/dev/null 2>&1; then
|
|
echo -e "${YELLOW}my-aliases.zsh is currently tracked by git${NC}"
|
|
ALIASES_TRACKED=true
|
|
else
|
|
echo -e "${GREEN}my-aliases.zsh is already untracked${NC}"
|
|
ALIASES_TRACKED=false
|
|
fi
|
|
|
|
# Check if .gitignore already has the entry
|
|
if grep -q "dotfiles/my-aliases.zsh" .gitignore 2>/dev/null; then
|
|
echo -e "${GREEN}.gitignore already contains entry for my-aliases.zsh${NC}"
|
|
GITIGNORE_UPDATED=true
|
|
else
|
|
echo -e "${YELLOW}.gitignore needs to be updated${NC}"
|
|
GITIGNORE_UPDATED=false
|
|
fi
|
|
|
|
# Prompt for confirmation
|
|
echo ""
|
|
echo -e "${YELLOW}Actions that will be performed:${NC}"
|
|
if [ "$ALIASES_TRACKED" = true ]; then
|
|
echo " 1. Remove dotfiles/my-aliases.zsh from git tracking"
|
|
fi
|
|
if [ "$GITIGNORE_UPDATED" = false ]; then
|
|
echo " 2. Add dotfiles/my-aliases.zsh to .gitignore"
|
|
fi
|
|
if [ "$ALIASES_TRACKED" = true ] || [ "$GITIGNORE_UPDATED" = false ]; then
|
|
echo " 3. Commit the changes"
|
|
else
|
|
echo " → No changes needed - cleanup already complete"
|
|
fi
|
|
|
|
echo ""
|
|
read -p "Continue? (y/N): " -n 1 -r
|
|
echo
|
|
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
|
echo -e "${YELLOW}Cleanup cancelled${NC}"
|
|
exit 0
|
|
fi
|
|
|
|
# Step 1: Remove from git tracking if needed
|
|
if [ "$ALIASES_TRACKED" = true ]; then
|
|
echo -e "${BLUE}=== Removing my-aliases.zsh from git tracking ===${NC}"
|
|
|
|
# Check if file exists and remove from tracking
|
|
if [ -f "dotfiles/my-aliases.zsh" ]; then
|
|
git rm --cached dotfiles/my-aliases.zsh
|
|
echo -e "${GREEN}✓ Removed dotfiles/my-aliases.zsh from git tracking${NC}"
|
|
else
|
|
# File doesn't exist but is tracked - remove from index anyway
|
|
git rm --cached dotfiles/my-aliases.zsh 2>/dev/null || true
|
|
echo -e "${GREEN}✓ Removed non-existent dotfiles/my-aliases.zsh from git index${NC}"
|
|
fi
|
|
fi
|
|
|
|
# Step 2: Update .gitignore if needed
|
|
if [ "$GITIGNORE_UPDATED" = false ]; then
|
|
echo -e "${BLUE}=== Updating .gitignore ===${NC}"
|
|
|
|
# Check if the "Generated dotfiles" section already exists
|
|
if grep -q "Generated dotfiles" .gitignore 2>/dev/null; then
|
|
# Add to existing section
|
|
if ! grep -q "dotfiles/my-aliases.zsh" .gitignore; then
|
|
sed -i '/# Generated dotfiles/a dotfiles/my-aliases.zsh' .gitignore
|
|
echo -e "${GREEN}✓ Added entry to existing Generated dotfiles section${NC}"
|
|
fi
|
|
else
|
|
# Create new section
|
|
echo "" >> .gitignore
|
|
echo "# Generated dotfiles - these are created dynamically by bootstrap process" >> .gitignore
|
|
echo "dotfiles/my-aliases.zsh" >> .gitignore
|
|
echo -e "${GREEN}✓ Added new Generated dotfiles section to .gitignore${NC}"
|
|
fi
|
|
fi
|
|
|
|
# Step 3: Check if we have changes to commit
|
|
if git diff --cached --quiet && git diff --quiet; then
|
|
echo -e "${GREEN}=== No changes to commit - cleanup already complete ===${NC}"
|
|
else
|
|
echo -e "${BLUE}=== Committing changes ===${NC}"
|
|
|
|
# Add .gitignore changes if any
|
|
git add .gitignore
|
|
|
|
# Create commit message
|
|
COMMIT_MSG="Remove my-aliases.zsh from tracking, add to .gitignore
|
|
|
|
- Remove dotfiles/my-aliases.zsh from git tracking to prevent conflicts
|
|
- Add to .gitignore as it's now dynamically generated by bootstrap
|
|
- Aliases are now created from my-aliases.zsh.original template"
|
|
|
|
# Commit the changes
|
|
git commit -m "$COMMIT_MSG"
|
|
echo -e "${GREEN}✓ Changes committed successfully${NC}"
|
|
fi
|
|
|
|
# Step 4: Verify the cleanup
|
|
echo -e "${BLUE}=== Verification ===${NC}"
|
|
|
|
# Check that file is no longer tracked
|
|
if ! git ls-files --error-unmatch dotfiles/my-aliases.zsh >/dev/null 2>&1; then
|
|
echo -e "${GREEN}✓ dotfiles/my-aliases.zsh is no longer tracked${NC}"
|
|
else
|
|
echo -e "${RED}✗ dotfiles/my-aliases.zsh is still tracked${NC}"
|
|
fi
|
|
|
|
# Check that .gitignore contains the entry
|
|
if grep -q "dotfiles/my-aliases.zsh" .gitignore; then
|
|
echo -e "${GREEN}✓ .gitignore contains entry for dotfiles/my-aliases.zsh${NC}"
|
|
else
|
|
echo -e "${RED}✗ .gitignore missing entry for dotfiles/my-aliases.zsh${NC}"
|
|
fi
|
|
|
|
# Show final git status
|
|
echo -e "${BLUE}=== Final Git Status ===${NC}"
|
|
git status --porcelain
|
|
|
|
# Check if we need to push
|
|
if git log --oneline origin/main..HEAD 2>/dev/null | grep -q "Remove my-aliases.zsh"; then
|
|
echo ""
|
|
echo -e "${YELLOW}=== Push Required ===${NC}"
|
|
echo -e "${YELLOW}You have local commits that need to be pushed to the remote repository.${NC}"
|
|
echo "Run: ${BLUE}git push origin main${NC}"
|
|
elif ! git remote >/dev/null 2>&1; then
|
|
echo -e "${YELLOW}No remote repository configured${NC}"
|
|
else
|
|
echo -e "${GREEN}Repository is up to date with remote${NC}"
|
|
fi
|
|
|
|
echo ""
|
|
echo -e "${GREEN}=== Cleanup Complete! ===${NC}"
|
|
echo -e "${GREEN}The my-aliases.zsh file is now properly configured as a generated file.${NC}"
|
|
echo ""
|
|
echo -e "${YELLOW}Next steps:${NC}"
|
|
echo "1. Push changes if needed: ${BLUE}git push origin main${NC}"
|
|
echo "2. Run bootstrap/setup on this system to regenerate aliases"
|
|
echo "3. The aliases file will now be created dynamically without git conflicts"
|