diff --git a/.dotter/global.toml b/.dotter/global.toml index 8df8a65..ff38ee2 100644 --- a/.dotter/global.toml +++ b/.dotter/global.toml @@ -32,7 +32,7 @@ depends = [] "fish/fish_plugins" = "~/.config/fish/fish_plugins" "fish/completions" = "~/.config/fish/completions" "fish/conf.d" = "~/.config/fish/conf.d" -"fish/functions" = "~/.config/fish/functions" +# Note: fish/functions is managed directly as a directory symlink in setup.sh [fish.variables] diff --git a/CLAUDE.md b/CLAUDE.md index 94114ee..f558455 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -10,3 +10,7 @@ Dotter automatically treats files with `{{` as templates. For files that contain target = "~/.config/nvim/lua/plugins/hop.lua" type = "symbolic" ``` + +## Directory Symlinks in setup.sh + +For directories where programs create new files that should be tracked (e.g., fish's `funcsave` command), use the `ensure_dir_symlink` function in `setup.sh` instead of Dotter. This symlinks the entire directory so dynamically created files are automatically tracked in the repository. diff --git a/fish/functions/ls.fish b/fish/functions/ls.fish new file mode 100644 index 0000000..cf6cab1 --- /dev/null +++ b/fish/functions/ls.fish @@ -0,0 +1,3 @@ +function ls --wraps=eza --description 'alias ls eza' + eza $argv +end diff --git a/setup.sh b/setup.sh index 89328bb..8dad085 100755 --- a/setup.sh +++ b/setup.sh @@ -2,6 +2,68 @@ set -eo pipefail +# Function to manage directory symlinks +# Usage: ensure_dir_symlink +# Args: +# source_dir: The actual directory to symlink to (must be absolute path) +# target_link: The symlink location to create +# force_flag: true/false - whether to force replacement if exists +ensure_dir_symlink() { + local source_dir="$1" + local target_link="$2" + local force_flag="$3" + + # Expand tilde in paths + target_link="${target_link/#\~/$HOME}" + source_dir="${source_dir/#\~/$HOME}" + + # Check if target exists + if [[ -e "$target_link" || -L "$target_link" ]]; then + # Check if it's already a symlink pointing to the right place + if [[ -L "$target_link" ]]; then + local current_target + current_target="$(readlink "$target_link")" + if [[ "$current_target" == "$source_dir" ]]; then + echo "✓ $target_link already symlinked correctly" + return 0 + else + # Symlink exists but points to wrong location + if [[ "$force_flag" == true ]]; then + echo "Replacing symlink $target_link (currently points to $current_target)" + rm "$target_link" + else + echo "⚠ Warning: $target_link exists but points to $current_target (expected $source_dir)" + echo " Run with --force-deploy to replace it" + return 0 + fi + fi + else + # Path exists but is not a symlink + if [[ "$force_flag" == true ]]; then + echo "Replacing $target_link with symlink (was a regular file/directory)" + rm -rf "$target_link" + else + echo "⚠ Warning: $target_link exists but is not a symlink" + echo " Run with --force-deploy to replace it" + return 0 + fi + fi + fi + + # Create parent directory if needed + local parent_dir + parent_dir="$(dirname "$target_link")" + if [[ ! -d "$parent_dir" ]]; then + echo "Creating parent directory: $parent_dir" + mkdir -p "$parent_dir" + fi + + # Create the symlink + echo "Creating symlink: $target_link -> $source_dir" + ln -s "$source_dir" "$target_link" + echo "✓ Successfully created symlink" +} + # Parse command line arguments RESET_CONFIG=false FORCE_DEPLOY=false @@ -192,6 +254,12 @@ else fi fi +# Manage directory symlinks (not handled by Dotter) +echo "" +echo "Setting up directory symlinks..." +DOTFILES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ensure_dir_symlink "$DOTFILES_DIR/fish/functions" "~/.config/fish/functions" "$FORCE_DEPLOY" + echo "" echo "✓ Setup complete!" echo ""