summaryrefslogtreecommitdiff
path: root/home-config/fish/functions/_fzf_preview_file.fish
diff options
context:
space:
mode:
authorRyan Schanzenbacher <ryan@rschanz.org>2024-04-05 11:57:45 -0400
committerRyan Schanzenbacher <ryan@rschanz.org>2024-04-05 11:57:45 -0400
commitb88d77fb2d0d5028a6f5670695dee6bec129501f (patch)
tree2536b0461d297e647cf07157641c9b1223339adf /home-config/fish/functions/_fzf_preview_file.fish
parent776a7ca55d2d2c3f396de91db1c6c3c5065012cd (diff)
ahhh sloppy fish, still needs fixing, esp with the vars
Diffstat (limited to 'home-config/fish/functions/_fzf_preview_file.fish')
-rw-r--r--home-config/fish/functions/_fzf_preview_file.fish43
1 files changed, 43 insertions, 0 deletions
diff --git a/home-config/fish/functions/_fzf_preview_file.fish b/home-config/fish/functions/_fzf_preview_file.fish
new file mode 100644
index 0000000..c926475
--- /dev/null
+++ b/home-config/fish/functions/_fzf_preview_file.fish
@@ -0,0 +1,43 @@
1# helper function for _fzf_search_directory and _fzf_search_git_status
2function _fzf_preview_file --description "Print a preview for the given file based on its file type."
3 # because there's no way to guarantee that _fzf_search_directory passes the path to _fzf_preview_file
4 # as one argument, we collect all the arguments into one single variable and treat that as the path
5 set -f file_path $argv
6
7 if test -L "$file_path" # symlink
8 # notify user and recurse on the target of the symlink, which can be any of these file types
9 set -l target_path (realpath "$file_path")
10
11 set_color yellow
12 echo "'$file_path' is a symlink to '$target_path'."
13 set_color normal
14
15 _fzf_preview_file "$target_path"
16 else if test -f "$file_path" # regular file
17 if set --query fzf_preview_file_cmd
18 # need to escape quotes to make sure eval receives file_path as a single arg
19 eval "$fzf_preview_file_cmd '$file_path'"
20 else
21 bat --style=numbers --color=always "$file_path"
22 end
23 else if test -d "$file_path" # directory
24 if set --query fzf_preview_dir_cmd
25 # see above
26 eval "$fzf_preview_dir_cmd '$file_path'"
27 else
28 # -A list hidden files as well, except for . and ..
29 # -F helps classify files by appending symbols after the file name
30 command ls -A -F "$file_path"
31 end
32 else if test -c "$file_path"
33 _fzf_report_file_type "$file_path" "character device file"
34 else if test -b "$file_path"
35 _fzf_report_file_type "$file_path" "block device file"
36 else if test -S "$file_path"
37 _fzf_report_file_type "$file_path" socket
38 else if test -p "$file_path"
39 _fzf_report_file_type "$file_path" "named pipe"
40 else
41 echo "$file_path doesn't exist." >&2
42 end
43end