feat(task): add symlink and directory management utilities

- Introduce `create-symlink`, `create-symlink-dir`, and `create-symlink-files` functions for managing symlinks
- Add `ensure-directory` utility to ensure directory paths exist
- Document new file management utilities in `library.md`
- Follow existing code style and documentation format
This commit is contained in:
Janik von Rotz committed 2025-11-23 15:51:28 +01:00
1 parent 600dbea955
commit ab07e6bd71
5 files changed
+93

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
create-symlink() {
local source="$1"
local target="$2"
# Remove existing file/directory if it exists
if [[ -e "$target" || -L "$target" ]]; then
rm -rf "$target"
fi
# Create parent directory if needed
local parent_dir=$(dirname "$target")
ensure-directory "$parent_dir"
# Create the symlink
ln -sf "$source" "$target"
}
+18
View File
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
create-symlink-dir() {
local source_dir="$1"
local target_dir="$2"
# Remove existing directory if it exists
if [[ -e "$target_dir" || -L "$target_dir" ]]; then
rm -rf "$target_dir"
fi
# Create parent directory if needed
local parent_dir=$(dirname "$target_dir")
ensure-directory "$parent_dir"
# Create symlink to directory
ln -sf "$source_dir" "$target_dir"
}
+25
View File
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
create-symlink-files() {
local source_pattern="$1"
local target_dir="$2"
# Create target directory
ensure-directory "$target_dir"
# Link each file in the source pattern
for source_file in $source_pattern; do
if [[ -f "$source_file" ]]; then
local filename=$(basename "$source_file")
local target_file="$target_dir/$filename"
# Remove existing file if it exists
if [[ -e "$target_file" || -L "$target_file" ]]; then
rm -f "$target_file"
fi
# Create the symlink
ln -sf "$source_file" "$target_file"
fi
done
}
+6
View File
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
ensure-directory() {
local dir="$1"
[[ ! -d "$dir" ]] && mkdir -p "$dir"
}