Better link handling in fzgo functions

This commit is contained in:
Thomas Avé 2025-01-28 01:41:03 +01:00
parent 1b24ccb8b9
commit 3482265bd6
1 changed files with 11 additions and 13 deletions

View File

@ -19,12 +19,11 @@ local function get_entries() {
return return
fi fi
for entry in "$XDG_CONFIG_HOME/fzgo/entries/$file_type"/*; do for entry in "$XDG_CONFIG_HOME/fzgo/entries/$file_type"/*; do
# If the file is a symlink to a directory, we want to list the directory
if [ -L "$entry" ]; then if [ -L "$entry" ]; then
target=$(realpath "$entry") entry=$(realpath "$entry")
if [ -d "$target" ]; then end
fd . "$target" -t "$file_type" if [ -d "$entry" ]; then
fi fd . "$entry" -t "$file_type"
else else
cat "$entry" cat "$entry"
fi fi
@ -42,15 +41,14 @@ function fzgo_update_cache() {
for entry in "$file_type_dir"/*; do for entry in "$file_type_dir"/*; do
file_type=$(basename "$file_type_dir") file_type=$(basename "$file_type_dir")
mkdir -p "$XDG_CACHE_HOME/fzgo/entries/$file_type" mkdir -p "$XDG_CACHE_HOME/fzgo/entries/$file_type"
# If the file is a symlink to a directory, we want to list the directory
if [ -L "$entry" ]; then if [ -L "$entry" ]; then
target=$(realpath "$entry") entry=$(realpath "$entry")
if [ -d "$target" ]; then end
out_file="$(echo "$target" | sed 's\/\|\g')" if [ -d "$entry" ]; then
out_file="$XDG_CACHE_HOME/fzgo/entries/$file_type/$out_file" out_file="$(echo "$entry" | sed 's\/\|\g')"
mkdir -p "$(dirname \"$out_file\")" out_file="$XDG_CACHE_HOME/fzgo/entries/$file_type/$out_file"
fd . "$target" -t "$file_type" > "$out_file" mkdir -p "$(dirname \"$out_file\")"
fi fd . "$entry" -t "$file_type" > "$out_file"
fi fi
done done
done done