diff --git a/DOTFILES_IMPROVEMENTS.md b/DOTFILES_IMPROVEMENTS.md new file mode 100644 index 0000000..f90fc4c --- /dev/null +++ b/DOTFILES_IMPROVEMENTS.md @@ -0,0 +1,285 @@ +# Dotfiles Repository Improvements + +## Overview +Your dotfiles repository has a solid foundation with support for multiple tools (zsh, vim, tmux, git) and cross-platform compatibility (macOS and Linux). Here are suggested improvements organized by category. + +## 🚀 Quick Wins + +### 1. **Fix Duplicate Vim Settings** +In `vim/vimrc.symlink`, lines 88-89 and 108-109 duplicate the same settings: +```vim +" Allow per directory .vimrc configurations. +set exrc +set secure +``` +Remove the second occurrence. + +### 2. **Consolidate PATH Exports in zshrc** +You have many individual PATH exports that could be consolidated. Consider using an array approach: +```bash +# Define all paths in an array +typeset -U path_additions=( + "$HOME/bin" + "$HOME/.dotfiles/bin" + "$HOME/.composer/vendor/bin" + "$HOME/.config/composer/vendor/bin" + "$HOME/.yarn/bin" + "$HOME/.nvm" + "$HOME/.pub-cache/bin" + "$HOME/bin/google-cloud-sdk/bin" +) + +# Add them to PATH in one go +for p in $path_additions; do + [[ -d "$p" ]] && PATH="$p:$PATH" +done +export PATH +``` + +### 3. **Add Missing Git Configurations** +Consider adding these useful git settings: +```gitconfig +[pull] + rebase = true +[fetch] + prune = true +[init] + defaultBranch = main +[rebase] + autoStash = true +``` + +## 📁 Structure & Organization + +### 4. **Create a Proper Installation System** +Instead of a single bootstrap script, consider a modular approach: +``` +script/ +├── bootstrap # Main entry point +├── install/ +│ ├── common.sh # Common functions +│ ├── macos.sh # macOS-specific +│ ├── linux.sh # Linux-specific +│ ├── node.sh # Node.js setup +│ ├── php.sh # PHP setup +│ └── vim.sh # Vim plugins +└── uninstall # Cleanup script +``` + +### 5. **Add Configuration for Modern Tools** +Create configurations for tools you're already installing: +- `starship/starship.toml` - Consider migrating from spaceship to Starship (faster, more features) +- `gh/config.yml` - GitHub CLI configuration +- `fzf/` - FZF configuration and key bindings + +## 🔧 Functionality Improvements + +### 6. **Enhance ZSH Configuration** +```bash +# Add these useful options to zshrc +setopt HIST_EXPIRE_DUPS_FIRST +setopt HIST_IGNORE_DUPS +setopt HIST_IGNORE_SPACE +setopt HIST_VERIFY +setopt SHARE_HISTORY +setopt APPEND_HISTORY + +# Better history settings +HISTSIZE=50000 +SAVEHIST=50000 + +# Add useful functions +mkcd() { mkdir -p "$@" && cd "$_"; } +``` + +### 7. **Improve Vim Configuration** +```vim +" Add persistent undo +set undofile +set undodir=~/.vim/undo + +" Better search settings +set ignorecase +set smartcase + +" Modern clipboard integration +set clipboard=unnamedplus + +" Consider migrating to vim-plug's on-demand loading +Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } +``` + +### 8. **Enhance Tmux Configuration** +```tmux +# Add mouse support (modern tmux) +set -g mouse on + +# Better status bar +set -g status-interval 1 +set -g status-position top + +# Automatic window renaming +set-option -g automatic-rename on +set-option -g automatic-rename-format '#{b:pane_current_path}' + +# Plugin manager (TPM) +set -g @plugin 'tmux-plugins/tpm' +set -g @plugin 'tmux-plugins/tmux-sensible' +set -g @plugin 'tmux-plugins/tmux-resurrect' +``` + +## 🛡️ Security & Best Practices + +### 9. **Add Security Checks** +```bash +# In bootstrap script +check_command() { + if ! command -v "$1" &> /dev/null; then + echo "❌ $1 is required but not installed." + return 1 + fi + return 0 +} + +# Verify checksums for downloaded files +verify_checksum() { + local file=$1 + local expected=$2 + local actual=$(sha256sum "$file" | cut -d' ' -f1) + [[ "$actual" == "$expected" ]] +} +``` + +### 10. **Environment Variable Management** +Create an `env/` directory for environment-specific configs: +``` +env/ +├── exports.zsh # Common exports +├── path.zsh # PATH management +├── aliases.zsh # All aliases +└── functions.zsh # Custom functions +``` + +## 🎯 Platform-Specific Improvements + +### 11. **Better Cross-Platform Support** +```bash +# In zshrc +case "$OSTYPE" in + darwin*) + source "$HOME/.dotfiles/zsh/macos.zsh" + ;; + linux*) + source "$HOME/.dotfiles/zsh/linux.zsh" + ;; +esac +``` + +### 12. **Conditional Tool Loading** +```bash +# Only load tool configs if they exist +[[ -f "$HOME/.cargo/env" ]] && source "$HOME/.cargo/env" +[[ -d "$HOME/.pyenv" ]] && eval "$(pyenv init -)" +command -v direnv &>/dev/null && eval "$(direnv hook zsh)" +``` + +## 📚 Documentation + +### 13. **Improve README** +- Add installation instructions +- Document available commands/aliases +- Add screenshots of the setup +- Include troubleshooting section +- Add requirements/dependencies table + +### 14. **Add Tool-Specific Documentation** +Create README files in each tool directory explaining: +- What the configuration does +- Key bindings/shortcuts +- Customization options + +## 🔄 Maintenance + +### 15. **Add Update Mechanism** +```bash +# script/update +#!/bin/bash +echo "🔄 Updating dotfiles..." +git pull origin main + +# Update submodules +git submodule update --init --recursive + +# Update Oh My Zsh +$ZSH/tools/upgrade.sh + +# Update vim plugins +vim +PlugUpdate +qall + +# Update global npm packages +npm update -g +``` + +### 16. **Version Management** +- Pin specific versions in bootstrap script +- Use `.tool-versions` for asdf/mise +- Document minimum version requirements + +## 🎨 Modern Alternatives + +Consider these modern alternatives to current tools: +- **zsh-autosuggestions** → Better command completion +- **zsh-completions** → More completions +- **exa/eza** → Modern replacement for ls +- **bat** → Cat with syntax highlighting +- **ripgrep** → Faster than ag +- **fd** → Faster find +- **delta** → Better git diff +- **lazygit** → Terminal UI for git + +## 🔍 Additional Suggestions + +### 17. **Add Debugging Support** +```bash +# Add to zshrc +export DOTFILES_DEBUG="${DOTFILES_DEBUG:-0}" +debug() { + [[ "$DOTFILES_DEBUG" == "1" ]] && echo "DEBUG: $*" +} +``` + +### 18. **Create Backup System** +Before making changes, backup existing configs: +```bash +backup_file() { + local file=$1 + if [[ -e "$file" ]]; then + cp "$file" "$file.backup.$(date +%Y%m%d_%H%M%S)" + fi +} +``` + +### 19. **Add Health Check** +```bash +# script/doctor +#!/bin/bash +echo "🏥 Checking dotfiles health..." +# Check symlinks +# Verify installations +# Test configurations +``` + +### 20. **Performance Optimization** +- Lazy load NVM (it's slow to initialize) +- Use `zsh-defer` for non-critical sourcing +- Profile zsh startup with `zprof` + +## 📝 Next Steps + +1. Start with quick wins (1-3) +2. Gradually implement structural improvements +3. Add documentation as you go +4. Test changes on both macOS and Linux +5. Consider using GNU Stow for symlink management + +This improvement plan balances immediate fixes with long-term enhancements while maintaining your existing workflow. \ No newline at end of file diff --git a/script/update b/script/update new file mode 100755 index 0000000..6856bfa --- /dev/null +++ b/script/update @@ -0,0 +1,160 @@ +#!/usr/bin/env bash +# +# update - Update all components of the dotfiles setup + +set -e + +DOTFILES_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +info() { + printf "${BLUE}==>${NC} %s\n" "$1" +} + +success() { + printf "${GREEN}✔${NC} %s\n" "$1" +} + +error() { + printf "${RED}✖${NC} %s\n" "$1" +} + +warn() { + printf "${YELLOW}⚠${NC} %s\n" "$1" +} + +# Update dotfiles repository +update_dotfiles() { + info "Updating dotfiles repository..." + cd "$DOTFILES_ROOT" + + # Check for uncommitted changes + if ! git diff-index --quiet HEAD --; then + warn "You have uncommitted changes in your dotfiles" + read -p "Stash changes and continue? [y/N] " -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]]; then + git stash push -m "Update script auto-stash $(date +%Y-%m-%d_%H:%M:%S)" + success "Changes stashed" + else + error "Update cancelled" + exit 1 + fi + fi + + git pull origin main + success "Dotfiles updated" + + # Update submodules if any + if [[ -f .gitmodules ]]; then + git submodule update --init --recursive + success "Submodules updated" + fi +} + +# Update Oh My Zsh +update_oh_my_zsh() { + if [[ -d "$HOME/.oh-my-zsh" ]]; then + info "Updating Oh My Zsh..." + (cd "$HOME/.oh-my-zsh" && git pull origin master) + success "Oh My Zsh updated" + fi +} + +# Update Zsh plugins +update_zsh_plugins() { + info "Updating Zsh plugins..." + + # Update spaceship prompt + if [[ -d "$HOME/.oh-my-zsh/custom/themes/spaceship-prompt" ]]; then + (cd "$HOME/.oh-my-zsh/custom/themes/spaceship-prompt" && git pull) + success "Spaceship prompt updated" + fi + + # Update syntax highlighting + if [[ -d "$HOME/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting" ]]; then + (cd "$HOME/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting" && git pull) + success "Zsh syntax highlighting updated" + fi +} + +# Update Vim plugins +update_vim_plugins() { + if command -v vim >/dev/null 2>&1; then + info "Updating Vim plugins..." + vim +PlugUpgrade +PlugUpdate +qall + success "Vim plugins updated" + fi +} + +# Update global npm packages +update_npm_packages() { + if command -v npm >/dev/null 2>&1; then + info "Updating global npm packages..." + npm update -g + success "npm packages updated" + fi +} + +# Update Homebrew packages (macOS) +update_homebrew() { + if [[ "$(uname)" == "Darwin" ]] && command -v brew >/dev/null 2>&1; then + info "Updating Homebrew packages..." + brew update + brew upgrade + brew cleanup + success "Homebrew packages updated" + fi +} + +# Update apt packages (Linux) +update_apt() { + if [[ -f /etc/debian_version ]] && command -v apt-get >/dev/null 2>&1; then + info "Updating apt packages..." + sudo apt-get update + sudo apt-get upgrade -y + sudo apt-get autoremove -y + success "apt packages updated" + fi +} + +# Update Composer packages +update_composer() { + if command -v composer >/dev/null 2>&1; then + info "Updating Composer packages..." + composer global update --with-dependencies + success "Composer packages updated" + fi +} + +# Main update process +main() { + echo "🚀 Updating dotfiles and dependencies..." + echo + + update_dotfiles + update_oh_my_zsh + update_zsh_plugins + update_vim_plugins + update_npm_packages + update_homebrew + update_apt + update_composer + + echo + success "All updates complete!" + + # Remind to restart shell + echo + warn "You may need to restart your shell for some changes to take effect" + warn "Run: exec \$SHELL" +} + +# Run main function +main "$@" \ No newline at end of file diff --git a/vim/vimrc.symlink b/vim/vimrc.symlink index c003543..615c6bd 100644 --- a/vim/vimrc.symlink +++ b/vim/vimrc.symlink @@ -105,10 +105,6 @@ set visualbell set backspace=eol,start,indent set nowrap -" Allow project spricifc .vimrc files -set exrc -set secure - " Tab settings. set expandtab set shiftwidth=2 diff --git a/zsh/path-consolidated.zsh.example b/zsh/path-consolidated.zsh.example new file mode 100644 index 0000000..b4c98ad --- /dev/null +++ b/zsh/path-consolidated.zsh.example @@ -0,0 +1,86 @@ +#!/usr/bin/env zsh +# Example: Consolidated PATH management for zshrc +# This demonstrates a cleaner approach to managing PATH exports + +# Define base paths that should come first +typeset -U base_paths=( + "/opt/homebrew/bin" + "/opt/homebrew/sbin" + "/usr/local/bin" + "/usr/local/sbin" +) + +# Define user-specific paths +typeset -U user_paths=( + "$HOME/bin" + "$HOME/.dotfiles/bin" + "$HOME/.composer/vendor/bin" + "$HOME/.config/composer/vendor/bin" + "$HOME/.yarn/bin" + "$HOME/.pub-cache/bin" + "$HOME/bin/google-cloud-sdk/bin" +) + +# Define language-specific paths +typeset -U lang_paths=( + "$GOPATH/bin" + "$GOROOT/bin" + "/usr/local/opt/ruby/bin" + "$HOME/bin/flutter/bin" +) + +# Define version-specific paths (these might change based on installed versions) +typeset -U version_paths=( + "/usr/local/opt/php@8.1/bin" + "/usr/local/opt/php@8.1/sbin" + "/opt/homebrew/opt/php@8.1/bin" + "/opt/homebrew/opt/php@8.1/sbin" +) + +# Function to add paths safely (only if they exist) +add_to_path() { + local position=$1 + shift + local paths=("$@") + + for p in $paths; do + if [[ -d "$p" ]]; then + if [[ "$position" == "prepend" ]]; then + PATH="$p:$PATH" + else + PATH="$PATH:$p" + fi + fi + done +} + +# Build PATH in order of priority +# Start with system PATH +PATH="/usr/bin:/bin:/usr/sbin:/sbin" + +# Add base paths (highest priority) +add_to_path prepend $base_paths + +# Add user paths +add_to_path prepend $user_paths + +# Add language paths +add_to_path append $lang_paths + +# Add version-specific paths +add_to_path append $version_paths + +# Remove duplicates and export +typeset -U PATH +export PATH + +# Optional: Debug function to show what's in PATH +show_path() { + echo "PATH contents:" + echo $PATH | tr ':' '\n' | nl +} + +# Optional: Function to check if a directory is in PATH +in_path() { + [[ ":$PATH:" == *":$1:"* ]] +} \ No newline at end of file