Update setup.sh to generate aliases dynamically without tracking

This commit is contained in:
Peter Wood
2025-05-28 20:01:49 +00:00
parent 08b766bec5
commit 8430686017

View File

@@ -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}"