mirror of
https://github.com/SeriousBug/dotfiles
synced 2025-12-06 21:12:08 -06:00
Add directory symlink support for fish functions
Allows setup.sh to symlink entire directories for cases where programs create new files that should be tracked (e.g., fish's funcsave command). Removes fish/functions from Dotter management in favor of direct symlink. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
a6b3290e76
commit
3bf9ba3318
|
|
@ -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]
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
3
fish/functions/ls.fish
Normal file
3
fish/functions/ls.fish
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
function ls --wraps=eza --description 'alias ls eza'
|
||||
eza $argv
|
||||
end
|
||||
68
setup.sh
68
setup.sh
|
|
@ -2,6 +2,68 @@
|
|||
|
||||
set -eo pipefail
|
||||
|
||||
# Function to manage directory symlinks
|
||||
# Usage: ensure_dir_symlink <source_dir> <target_link> <force_flag>
|
||||
# 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 ""
|
||||
|
|
|
|||
Loading…
Reference in a new issue