fzf preview script

This commit is contained in:
parent 3cc07734dc
commit 5eb0864916
2 changed files with 20 additions and 5 deletions

14
.config/scripts/preview-file.sh Executable file
View File

@ -0,0 +1,14 @@
if [[ -d $1 ]] ; then
echo "$(eza --tree --color=always $1 | head -200)"
exit
fi
filename=$(basename -- "$1")
extension="${filename##*.}"
case "$extension" in
png|jpg|webp) echo "$(timg -p quarter -g50x50 $1)" ;;
7z|zip|gz) echo "$(7z l $1)" ;;
*) echo "$(bat -n --color=always --line-range :500 $1)" ;;
esac

11
.zshrc
View File

@ -79,7 +79,7 @@ if command -v fd > /dev/null; then
} }
if command -v bat > /dev/null; then if command -v bat > /dev/null; then
export FZF_CTRL_T_OPTS="--preview 'bat -n --color=always --line-range :500 {}'" export FZF_CTRL_T_OPTS="--preview '~/.config/scripts/preview-file.sh {}'"
fi fi
if command -v eza > /dev/null; then if command -v eza > /dev/null; then
export FZF_ALT_C_OPTS="--preview 'eza --tree --color=always {} | head -200'" export FZF_ALT_C_OPTS="--preview 'eza --tree --color=always {} | head -200'"
@ -89,10 +89,11 @@ if command -v fd > /dev/null; then
shift shift
case "$command" in case "$command" in
cd) fzf --preview 'eza --tree --color=always {} | head -200' "$@" ;; cd) fzf --preview 'eza --tree --color=always {} | head -200' "$@" ;;
export|unset) fzf --preview "eval 'echo \$' {}" "$@" ;; export|unset) fzf --preview "eval 'echo \$'{}" "$@" ;;
ssh) fzf --preview 'dig {}' "$@" ;; ssh) fzf --preview 'dig {}' "$@" ;;
*) fzf --preview "--preview 'bat -n --color=always --line-range :500 {}'" "$@" ;; timg) fzf --preview 'timg -p quarter -g50x50 {}' "$@" ;;
*) fzf --preview "~/.config/scripts/preview-file.sh $@" ;;
esac esac
} }
fi fi