diff --git a/.config/scripts/preview-file.sh b/.config/scripts/preview-file.sh new file mode 100755 index 0000000..c311482 --- /dev/null +++ b/.config/scripts/preview-file.sh @@ -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 + diff --git a/.zshrc b/.zshrc index aacb4ea..1e2f0aa 100644 --- a/.zshrc +++ b/.zshrc @@ -79,7 +79,7 @@ if command -v fd > /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 if command -v eza > /dev/null; then export FZF_ALT_C_OPTS="--preview 'eza --tree --color=always {} | head -200'" @@ -89,10 +89,11 @@ if command -v fd > /dev/null; then shift case "$command" in - cd) fzf --preview 'eza --tree --color=always {} | head -200' "$@" ;; - export|unset) fzf --preview "eval 'echo \$' {}" "$@" ;; - ssh) fzf --preview 'dig {}' "$@" ;; - *) fzf --preview "--preview 'bat -n --color=always --line-range :500 {}'" "$@" ;; + cd) fzf --preview 'eza --tree --color=always {} | head -200' "$@" ;; + export|unset) fzf --preview "eval 'echo \$'{}" "$@" ;; + ssh) fzf --preview 'dig {}' "$@" ;; + timg) fzf --preview 'timg -p quarter -g50x50 {}' "$@" ;; + *) fzf --preview "~/.config/scripts/preview-file.sh $@" ;; esac } fi