Skip to content

Commit

Permalink
[Search directory] Properly show symlink info in file previews (#159)
Browse files Browse the repository at this point in the history
The files preview code is meant to display info about symlinks when previewing them. However, because test -f and test -d appear before test -L, the symlink message won't show for symlinks to regular files and directories. Fix this by moving the symlink case to the top.
  • Loading branch information
kidonng authored May 10, 2021
1 parent dd8e429 commit ef7db6c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions functions/__fzf_preview_file.fish
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@ function __fzf_preview_file --description "Print a preview for the given file ba
# as one argument, we collect all the arguments into one single variable and treat that as the path
set file_path $argv

if test -f "$file_path" # regular file
if test -L "$file_path" # symlink
# notify user and recurse on the target of the symlink, which can be any of these file types
set -l target_path (realpath $file_path)

set_color yellow
echo "'$file_path' is a symlink to '$target_path'."
set_color normal

__fzf_preview_file "$target_path"
else if test -f "$file_path" # regular file
if set --query fzf_preview_file_cmd
# need to escape quotes to make sure eval receives file_path as a single arg
eval $fzf_preview_file_cmd \"$file_path\"
Expand All @@ -20,15 +29,6 @@ function __fzf_preview_file --description "Print a preview for the given file ba
# -F helps classify files by appending symbols after the file name
command ls -A -F "$file_path"
end
else if test -L "$file_path" # symlink
# notify user and recurse on the target of the symlink, which can be any of these file types
set -l target_path (realpath $file_path)
set_color yellow
echo "'$file_path' is a symlink to '$target_path'."
set_color normal
__fzf_preview_file "$target_path"
else if test -c "$file_path"
__fzf_report_file_type "$file_path" "character device file"
else if test -b "$file_path"
Expand Down

0 comments on commit ef7db6c

Please sign in to comment.