Refactor alias management and improve bootstrap process for Zsh

This commit is contained in:
Peter Wood
2025-05-19 16:26:36 -04:00
parent 34260be460
commit b674c0a95b
5 changed files with 111 additions and 10 deletions

View File

@@ -76,8 +76,15 @@ eval "$(zoxide init zsh)"
# For a full list of active aliases, run `alias`. # For a full list of active aliases, run `alias`.
# Load custom aliases # Load custom aliases
# Define ZSH_CUSTOM if not already defined
if [ -z "$ZSH_CUSTOM" ]; then
ZSH_CUSTOM="$HOME/.oh-my-zsh/custom"
fi
if [ -f "$ZSH_CUSTOM/aliases.zsh" ]; then if [ -f "$ZSH_CUSTOM/aliases.zsh" ]; then
source "$ZSH_CUSTOM/aliases.zsh" source "$ZSH_CUSTOM/aliases.zsh"
elif [ -f "$HOME/.oh-my-zsh/custom/aliases.zsh" ]; then
source "$HOME/.oh-my-zsh/custom/aliases.zsh"
fi fi
# set directory to home # set directory to home

View File

@@ -11,6 +11,6 @@ alias update="/home/acedanger/shell/update.sh"
alias dcdn="docker compose down" alias dcdn="docker compose down"
alias dcupd="docker compose up -d" alias dcupd="docker compose up -d"
alias lzd="lazydocker" alias lzd="lazydocker"
alias cat="batcat" alias cat="bat"
alias fd="fdfind" alias fd="fd"
alias fzf="fzf --preview='batcat {}'" alias fzf="fzf --preview='bat {}'"

View File

@@ -0,0 +1,16 @@
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]'"
alias plex="/home/acedanger/shell/plex.sh"
alias update="/home/acedanger/shell/update.sh"
alias dcdn="docker compose down"
alias dcupd="docker compose up -d"
alias lzd="lazydocker"
alias cat="batcat"
alias fd="fdfind"
alias fzf="fzf --preview='batcat {}'"

View File

@@ -75,4 +75,13 @@ chmod +x "$DOTFILES_DIR/setup/setup.sh"
# Run setup script # Run setup script
"$DOTFILES_DIR/setup/setup.sh" "$DOTFILES_DIR/setup/setup.sh"
echo -e "${GREEN}Bootstrap completed! Please restart your terminal for changes to take effect.${NC}" # Source the aliases file if it exists to make aliases available in the current session
ZSH_CUSTOM="$HOME/.oh-my-zsh/custom"
ALIASES_FILE="$ZSH_CUSTOM/aliases.zsh"
if [ -f "$ALIASES_FILE" ]; then
echo -e "${YELLOW}Loading aliases into current session...${NC}"
source "$ALIASES_FILE"
fi
echo -e "${GREEN}Bootstrap completed! Your aliases have been set up.${NC}"
echo -e "${YELLOW}Tip: Run 'source ~/.zshrc' or start a new terminal session to use all zsh features.${NC}"

View File

@@ -39,7 +39,7 @@ determine_pkg_manager() {
# Set up package management based on OS # Set up package management based on OS
if [ "$OS_NAME" = "fedora" ]; then if [ "$OS_NAME" = "fedora" ]; then
echo -e "${YELLOW}Setting up Fedora repositories and package management...${NC}" echo -e "${YELLOW}Setting up Fedora Tsrepositories and package management...${NC}"
# Install prerequisites for Fedora # Install prerequisites for Fedora
sudo dnf install -y wget gpg sudo dnf install -y wget gpg
@@ -135,7 +135,7 @@ mapfile -t pkgs < <(grep -v '^//' "$SCRIPT_DIR/packages.list" | grep -v -e '^$')
# Map Debian/Ubuntu package names to Fedora equivalents if needed # Map Debian/Ubuntu package names to Fedora equivalents if needed
declare -A fedora_pkg_map declare -A fedora_pkg_map
fedora_pkg_map["bat"]="bat" fedora_pkg_map["bat"]="bat"
fedora_pkg_map["fd-find"]="fd-find" fedora_pkg_map["fd-find"]="fd" # On Fedora, the package is called 'fd'
# Add more package mappings as needed # Add more package mappings as needed
# Process the package list based on OS # Process the package list based on OS
@@ -287,11 +287,74 @@ ln -sf "$DOTFILES_SUBDIR/.nanorc" "$HOME/.nanorc" 2>/dev/null || true
ln -sf "$DOTFILES_SUBDIR/.profile" "$HOME/.profile" 2>/dev/null || true ln -sf "$DOTFILES_SUBDIR/.profile" "$HOME/.profile" 2>/dev/null || true
ln -sf "$DOTFILES_SUBDIR/.gitconfig" "$HOME/.gitconfig" 2>/dev/null || true ln -sf "$DOTFILES_SUBDIR/.gitconfig" "$HOME/.gitconfig" 2>/dev/null || true
if [ "$OS_NAME" = "fedora" ]; then # Create custom aliases based on available commands
echo -e "${YELLOW}Setting up Fedora-specific configurations...${NC}" echo -e "${YELLOW}Setting up custom aliases...${NC}"
echo -e "${GREEN}Fedora-specific setup completed.${NC}" 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"
# 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"
# Function to check for command existence and add appropriate alias
add_conditional_alias() {
local cmd_name=$1
local debian_cmd=$2
local fedora_cmd=$3
local alias_line=$4
echo -e "${YELLOW}Checking for $cmd_name command...${NC}"
if command -v "$debian_cmd" &> /dev/null; then
echo "alias $cmd_name=\"$debian_cmd\"" >> "$ALIASES_FILE"
echo -e "${GREEN}Using $debian_cmd for $cmd_name alias${NC}"
return 0
elif command -v "$fedora_cmd" &> /dev/null; then
echo "alias $cmd_name=\"$fedora_cmd\"" >> "$ALIASES_FILE"
echo -e "${GREEN}Using $fedora_cmd for $cmd_name alias${NC}"
return 0
else
echo -e "${YELLOW}Neither $debian_cmd nor $fedora_cmd found. Skipping $cmd_name alias.${NC}"
return 1
fi
}
# Set up the cat/bat alias
add_conditional_alias "cat" "batcat" "bat"
# Set up the fd alias
add_conditional_alias "fd" "fdfind" "fd"
# Set up fzf preview with correct bat command
if command -v fzf &> /dev/null; then
if command -v batcat &> /dev/null; then
echo "alias fzf=\"fzf --preview='batcat {}'\"" >> "$ALIASES_FILE"
echo -e "${GREEN}Using batcat for fzf preview${NC}"
elif command -v bat &> /dev/null; then
echo "alias fzf=\"fzf --preview='bat {}'\"" >> "$ALIASES_FILE"
echo -e "${GREEN}Using bat for fzf preview${NC}"
else
echo "alias fzf=\"fzf\"" >> "$ALIASES_FILE"
echo -e "${YELLOW}No bat/batcat found for fzf preview. Using basic fzf alias.${NC}"
fi
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
# Make sure the aliases file gets sourced immediately in the current shell
echo -e "${GREEN}Custom aliases configured for $OS_NAME.${NC}"
# Set Zsh as default shell if not already set # Set Zsh as default shell if not already set
if [[ "$SHELL" != *"zsh"* ]]; then if [[ "$SHELL" != *"zsh"* ]]; then
echo -e "${YELLOW}Setting Zsh as default shell...${NC}" echo -e "${YELLOW}Setting Zsh as default shell...${NC}"
@@ -309,5 +372,11 @@ if [[ "$SHELL" != *"zsh"* ]]; then
fi fi
fi fi
echo -e "${GREEN}Setup completed successfully for $OS_NAME $OS_VERSION!${NC}" # Display useful information about the setup
echo -e "\n${GREEN}=== Setup Summary ===${NC}"
echo -e "${GREEN}OS: $OS_NAME $OS_VERSION${NC}"
echo -e "${GREEN}Package Manager: $PKG_MANAGER${NC}"
echo -e "${GREEN}Shell: $(basename "$SHELL") → zsh${NC}"
echo -e "\n${GREEN}Setup completed successfully for $OS_NAME $OS_VERSION!${NC}"
echo -e "${YELLOW}Note: You may need to log out and log back in for all changes to take effect.${NC}" echo -e "${YELLOW}Note: You may need to log out and log back in for all changes to take effect.${NC}"