From 08b766bec5c0d1110168f33c5c8db666e0d5d57e Mon Sep 17 00:00:00 2001 From: Peter Wood Date: Wed, 28 May 2025 19:57:57 +0000 Subject: [PATCH 1/3] Remove my-aliases.zsh from tracking - now generated dynamically by bootstrap --- .gitignore | 3 +++ dotfiles/my-aliases.zsh | 24 ------------------------ 2 files changed, 3 insertions(+), 24 deletions(-) delete mode 100644 dotfiles/my-aliases.zsh diff --git a/.gitignore b/.gitignore index 611e363..7b94e27 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,6 @@ crontab/crontab-backups/*/archive/ # backblaze cli # can be downloaded from immich/b2-linux + +# Generated dotfiles - these are created dynamically by bootstrap process +dotfiles/my-aliases.zsh diff --git a/dotfiles/my-aliases.zsh b/dotfiles/my-aliases.zsh deleted file mode 100644 index b24b491..0000000 --- a/dotfiles/my-aliases.zsh +++ /dev/null @@ -1,24 +0,0 @@ -alias py=python3 -alias gpull="git pull" -alias gpush="git push" -alias gc="git commit" -alias gcm="git commit -m" - -alias ll="ls -laFh --group-directories-first --color=auto" -alias findzombie="ps -A -ostat,pid,ppid | grep -e '[zZ]'" -# 🎬 Plex Media Server Management - Sexy Edition -alias plex="/home/acedanger/shell/plex/plex.sh" -alias px="/home/acedanger/shell/plex/plex.sh" # Quick shortcut -alias plex-start="/home/acedanger/shell/plex/plex.sh start" # Start Plex -alias plex-stop="/home/acedanger/shell/plex/plex.sh stop" # Stop Plex -alias plex-restart="/home/acedanger/shell/plex/plex.sh restart" # Restart Plex -alias plex-status="/home/acedanger/shell/plex/plex.sh status" # Status check -alias plex-web="xdg-open http://localhost:32400/web" # Open web UI in browser -alias update="/home/acedanger/shell/update.sh" -alias dcdn="docker compose down" -alias dcupd="docker compose up -d" -alias dcpull="docker compose pull" -alias lzd="lazydocker" -alias cat="batcat" -alias fd="fdfind" -alias fzf="fzf --preview='batcat {}'" From 8430686017d7886160f7c5394dfb4edafa8264d6 Mon Sep 17 00:00:00 2001 From: Peter Wood Date: Wed, 28 May 2025 20:01:49 +0000 Subject: [PATCH 2/3] Update setup.sh to generate aliases dynamically without tracking --- setup/setup.sh | 54 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/setup/setup.sh b/setup/setup.sh index 7eda314..7075bce 100755 --- a/setup/setup.sh +++ b/setup/setup.sh @@ -311,11 +311,46 @@ ZSH_CUSTOM="$HOME/.oh-my-zsh/custom" ALIASES_FILE="$ZSH_CUSTOM/aliases.zsh" mkdir -p "$ZSH_CUSTOM" -# Create a copy of the original aliases file for backup -cp "$DOTFILES_SUBDIR/my-aliases.zsh" "$ALIASES_FILE.bak" +# Create the aliases file from template if it exists, otherwise create a basic one +if [ -f "$DOTFILES_SUBDIR/my-aliases.zsh.original" ]; then + # Use the original template as the base + cp "$DOTFILES_SUBDIR/my-aliases.zsh.original" "$ALIASES_FILE.bak" + # Filter out dynamic aliases that will be added based on system + grep -v "^alias cat=" "$DOTFILES_SUBDIR/my-aliases.zsh.original" | \ + grep -v "^alias fd=" | \ + grep -v "^alias fzf=" | \ + grep -v "^alias ls=" | \ + grep -v "^alias ll=" | \ + grep -v "^alias la=" | \ + grep -v "^alias l=" > "$ALIASES_FILE" +else + # Create a basic aliases file with common aliases + cat > "$ALIASES_FILE" << 'EOF' +# Generated aliases file - system specific +alias py=python3 +alias gpull="git pull" +alias gpush="git push" +alias gc="git commit" +alias gcm="git commit -m" +alias findzombie="ps -A -ostat,pid,ppid | grep -e '[zZ]'" -# First, copy all general aliases except those we'll modify based on OS -grep -v "alias cat=" "$DOTFILES_SUBDIR/my-aliases.zsh" | grep -v "alias fd=" | grep -v "alias fzf=" > "$ALIASES_FILE" +# Plex Media Server Management +alias plex="/home/acedanger/shell/plex/plex.sh" +alias px="/home/acedanger/shell/plex/plex.sh" +alias plex-start="/home/acedanger/shell/plex/plex.sh start" +alias plex-stop="/home/acedanger/shell/plex/plex.sh stop" +alias plex-restart="/home/acedanger/shell/plex/plex.sh restart" +alias plex-status="/home/acedanger/shell/plex/plex.sh status" +alias plex-web="xdg-open http://localhost:32400/web" + +# System aliases +alias update="/home/acedanger/shell/update.sh" +alias dcdn="docker compose down" +alias dcupd="docker compose up -d" +alias dcpull="docker compose pull" +alias lzd="lazydocker" +EOF +fi # Function to check for command existence and add appropriate alias add_conditional_alias() { @@ -360,15 +395,8 @@ if command -v fzf &> /dev/null; then fi fi -# Also create a symlink from the custom aliases file back to the dotfiles directory for persistence -# This allows changes made to aliases.zsh to be tracked in the dotfiles repo -echo -e "${YELLOW}Creating symlink to save customized aliases back to dotfiles...${NC}" -if [ -f "$ALIASES_FILE" ]; then - # Save a copy of the original for reference - cp "$DOTFILES_SUBDIR/my-aliases.zsh" "$DOTFILES_SUBDIR/my-aliases.zsh.original" 2>/dev/null || true - # Replace the my-aliases.zsh with the new customized one - cp "$ALIASES_FILE" "$DOTFILES_SUBDIR/my-aliases.zsh" -fi +# Note: my-aliases.zsh is now generated dynamically and not tracked in git +# The generated aliases.zsh file in ~/.oh-my-zsh/custom/ contains the system-specific aliases # Make sure the aliases file gets sourced immediately in the current shell echo -e "${GREEN}Custom aliases configured for $OS_NAME.${NC}" From 90a489c823cb74b252cb6ca525ea290c429c401d Mon Sep 17 00:00:00 2001 From: Peter Wood Date: Wed, 28 May 2025 20:17:44 +0000 Subject: [PATCH 3/3] feat: Add cleanup script for my-aliases.zsh tracking and update documentation --- cleanup-alias-tracking.sh | 176 +++++++++++++++++++++ completions/backup-scripts-completion.bash | 0 docs/cleanup-alias-tracking.md | 148 +++++++++++++++++ setup/setup.sh | 6 +- 4 files changed, 327 insertions(+), 3 deletions(-) create mode 100755 cleanup-alias-tracking.sh mode change 100644 => 100755 completions/backup-scripts-completion.bash create mode 100644 docs/cleanup-alias-tracking.md diff --git a/cleanup-alias-tracking.sh b/cleanup-alias-tracking.sh new file mode 100755 index 0000000..f18b71d --- /dev/null +++ b/cleanup-alias-tracking.sh @@ -0,0 +1,176 @@ +#!/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" diff --git a/completions/backup-scripts-completion.bash b/completions/backup-scripts-completion.bash old mode 100644 new mode 100755 diff --git a/docs/cleanup-alias-tracking.md b/docs/cleanup-alias-tracking.md new file mode 100644 index 0000000..61fec57 --- /dev/null +++ b/docs/cleanup-alias-tracking.md @@ -0,0 +1,148 @@ +# Alias File Tracking Cleanup + +## Overview + +The `cleanup-alias-tracking.sh` script is designed to clean up the git repository on systems where `dotfiles/my-aliases.zsh` was previously tracked but should now be treated as a dynamically generated file. + +## Problem Context + +Originally, `my-aliases.zsh` was tracked in git, but this caused conflicts when the bootstrap process tried to update it with system-specific aliases. The file is now: + +- **Generated dynamically** from `my-aliases.zsh.original` template +- **Customized per system** (debian vs ubuntu vs fedora) +- **Should not be tracked** in git to prevent conflicts + +## What This Script Does + +1. **Removes git tracking** of `dotfiles/my-aliases.zsh` +2. **Updates .gitignore** to ignore the file +3. **Commits the changes** with a descriptive message +4. **Verifies the cleanup** was successful +5. **Provides next steps** for pushing and regenerating aliases + +## Usage + +### On Each System You Manage + +```bash +# Navigate to your shell repository +cd ~/shell + +# Run the cleanup script +./cleanup-alias-tracking.sh +``` + +### What You'll See + +The script will: +- Show current git status +- Check if the file is currently tracked +- Check if .gitignore already has the entry +- Ask for confirmation before making changes +- Perform the cleanup +- Verify the results + +### Example Output + +``` +=== Alias File Tracking Cleanup Script === +This script will remove my-aliases.zsh from git tracking +and update .gitignore to prevent future conflicts. + +=== Current Git Status === +M dotfiles/my-aliases.zsh + +my-aliases.zsh is currently tracked by git +.gitignore needs to be updated + +Actions that will be performed: + 1. Remove dotfiles/my-aliases.zsh from git tracking + 2. Add dotfiles/my-aliases.zsh to .gitignore + 3. Commit the changes + +Continue? (y/N): y + +=== Removing my-aliases.zsh from git tracking === +✓ Removed dotfiles/my-aliases.zsh from git tracking + +=== Updating .gitignore === +✓ Added new Generated dotfiles section to .gitignore + +=== Committing changes === +✓ Changes committed successfully + +=== Verification === +✓ dotfiles/my-aliases.zsh is no longer tracked +✓ .gitignore contains entry for dotfiles/my-aliases.zsh + +=== Final Git Status === +(clean working directory) + +=== Cleanup Complete! === +``` + +## After Running the Script + +1. **Push the changes** to your repository: + ```bash + git push origin main + ``` + +2. **Regenerate the aliases** on the system: + ```bash + # Run setup to regenerate aliases from template + ~/shell/setup/setup.sh + ``` + +3. **Verify aliases work**: + ```bash + # Source your shell config or start a new terminal + source ~/.zshrc + + # Test aliases + ll # Should work if aliases were generated correctly + ``` + +## Safety Features + +- **Confirmation prompt** before making any changes +- **Git status checks** to show what will be affected +- **Verification steps** to ensure cleanup was successful +- **No data loss** - the script only removes tracking, not the actual file +- **Idempotent** - safe to run multiple times + +## Troubleshooting + +### Script Says "No changes needed" + +This means the cleanup was already done on this system. You can verify by checking: +```bash +git ls-files | grep my-aliases.zsh # Should return nothing +grep "my-aliases.zsh" .gitignore # Should show the ignore entry +``` + +### File Still Shows as Modified + +If `my-aliases.zsh` still shows as modified after cleanup: +1. This is normal - the file exists locally but is now ignored +2. Delete the local file: `rm dotfiles/my-aliases.zsh` +3. Run setup to regenerate: `~/shell/setup/setup.sh` + +### Merge Conflicts on Other Systems + +If you get merge conflicts when pulling: +1. Run this cleanup script first +2. Then pull the latest changes +3. The conflicts should be resolved automatically + +## Files Modified + +- **dotfiles/my-aliases.zsh** - Removed from git tracking +- **.gitignore** - Added ignore entry with explanatory comment +- **Git history** - One commit documenting the change + +## Related Files + +- **dotfiles/my-aliases.zsh.original** - Template file (remains tracked) +- **setup/setup.sh** - Script that generates aliases from template +- **~/.oh-my-zsh/custom/aliases.zsh** - Final generated aliases location diff --git a/setup/setup.sh b/setup/setup.sh index 7075bce..dff985d 100755 --- a/setup/setup.sh +++ b/setup/setup.sh @@ -285,13 +285,13 @@ COMPLETION_SCRIPT="$DOTFILES_DIR/completions/backup-scripts-completion.bash" if [ -f "$COMPLETION_SCRIPT" ]; then # Create completions directory in home mkdir -p "$HOME/.local/share/bash-completion/completions" - + # Copy completion script to user's completion directory cp "$COMPLETION_SCRIPT" "$HOME/.local/share/bash-completion/completions/" - + # Make sure it's executable chmod +x "$HOME/.local/share/bash-completion/completions/backup-scripts-completion.bash" - + echo -e "${GREEN}Bash completion script installed successfully!${NC}" else echo -e "${YELLOW}Warning: Bash completion script not found at $COMPLETION_SCRIPT${NC}"