Skip to content

Commit 972c0cc

Browse files
peterpfShaun Prince
authored andcommitted
fix: Fix get_full_path for complex filenames (nix store paths)
Fixed path resolution for files with complex filenames like those in the nix store (e.g., /nix/store/1ayxpfhvvhq1c454acsgf4vb84m5mnr4-hm_image.png). The previous implementation incorrectly resolved this to /nix/store/hm_image.png. Cherry-picked from dylanaraps#2425 Original author: Peter Egger (peterpf)
1 parent 7e01ba3 commit 972c0cc

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

neofetch

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4601,23 +4601,26 @@ get_full_path() {
46014601
# If the file exists in the current directory, stop here.
46024602
[[ -f "${PWD}/${1}" ]] && { printf '%s\n' "${PWD}/${1}"; return; }
46034603

4604-
! cd "${1%/*}" && {
4605-
err "Error: Directory '${1%/*}' doesn't exist or is inaccessible"
4604+
# Extract the directory path and filename
4605+
local dir_path="${1%/*}"
4606+
local file_name="${1##*/}"
4607+
4608+
# Change directory to the path (if it exists)
4609+
! cd "$dir_path" && {
4610+
err "Error: Directory '$dir_path' doesn't exist or is inaccessible"
46064611
err " Check that the directory exists or try another directory."
46074612
exit 1
46084613
}
46094614

4610-
local full_dir="${1##*/}"
4611-
46124615
# Iterate down a (possible) chain of symlinks.
4613-
while [[ -L "$full_dir" ]]; do
4614-
full_dir="$(readlink "$full_dir")"
4615-
cd "${full_dir%/*}" || exit
4616-
full_dir="${full_dir##*/}"
4616+
while [[ -L "$file_name" ]]; do
4617+
file_name="$(readlink "$file_name")"
4618+
cd "${file_name%/*}" || exit
4619+
file_name="${file_name##*/}"
46174620
done
46184621

46194622
# Final directory.
4620-
full_dir="$(pwd -P)/${1/*\/}"
4623+
local full_dir="$(pwd -P)/$file_name"
46214624

46224625
[[ -e "$full_dir" ]] && printf '%s\n' "$full_dir"
46234626
}

0 commit comments

Comments
 (0)