cd ~.dotfiles git pull echo "Creating symbolic links for dotfiles..." # Function to create symlinks recursively create_symlinks() { local src_dir="$1" local target_dir="$2" # Create the target directory if it doesn't exist mkdir -p "$target_dir" # Handle .zsh_functions directory specially - link the whole directory if [ -d "$src_dir/.zsh_functions" ]; then local target_zsh_functions="$target_dir/.zsh_functions" # Remove existing directory or symlink if it exists if [ -e "$target_zsh_functions" ] || [ -L "$target_zsh_functions" ]; then echo "Removing existing: $target_zsh_functions" rm -rf "$target_zsh_functions" fi # Create symlink for the entire directory echo "Linking directory: $src_dir/.zsh_functions -> $target_zsh_functions" ln -s "$src_dir/.zsh_functions" "$target_zsh_functions" fi # Find all files and directories in the source directory, excluding .git, README.md, and .zsh_functions find "$src_dir" \( -not -path "*/\.git*" -and -not -name "README.md" -and -not -path "*/.zsh_functions/*" -and -not -path "*/.zsh_functions" \) -and \( -type f -o -type l \) | while read -r src_file; do # Get the relative path from src_dir rel_path="${src_file#$src_dir/}" # Construct the target file path target_file="$target_dir/$rel_path" # Create parent directories if they don't exist mkdir -p "$(dirname "$target_file")" # Remove existing file if it exists if [ -e "$target_file" ] || [ -L "$target_file" ]; then echo "Removing existing file: $target_file" rm -f "$target_file" fi # Create symlink echo "Linking: $src_file -> $target_file" ln -s "$src_file" "$target_file" done } # Call the function to create symlinks from dotfiles to home create_symlinks "$HOME/.dotfiles" "$HOME" echo "Dotfiles setup complete!"