Add preview toggle to fzf/fish

This commit is contained in:
ViViDboarder 2020-10-05 09:32:59 -07:00
parent cb2c0ea26d
commit a666ccf041
3 changed files with 21 additions and 8 deletions

View File

@ -0,0 +1,16 @@
# A function that can be used as the preview function for FZF to make fancy previews with syntax highlighting
function __fzf_preview
if file --mime "$argv" | grep -q binary
echo "$argv is a binary file"
else
if command --quiet --search bat
bat --color=always --line-range :500 "$argv"
else if command --quiet --search chroma
chroma "$argv" | head -250
else if command --quiet --search coderay
coderay "$argv" | head -250
else
head -250 "$argv"
end
end
end

View File

@ -1,8 +0,0 @@
# A function that can be used as the preview function for FZF to make fancy previews with syntax highlighting
function __fzf_preview
if file --mime "$argv" | grep -q binary
echo "$argv is a binary file"
else
coderay "$argv" ;or cat "$argv" 2> /dev/null | head -250
end
end

View File

@ -16,6 +16,11 @@ end
if [ -n "$FZF_DEFAULT_COMMAND" ]
set -gx FZF_CTRL_T_COMMAND "$FZF_DEFAULT_COMMAND \$dir"
end
set -gx FZF_DEFAULT_OPTS "
--preview-window=:hidden
--preview='__fzf_preview {}'
--bind '?:toggle-preview'
"
# Vim Colors so that they can be set by env
set -q VIM_COLOR; set -gx VIM_COLOR (eval $HOME/bin/get_vim_colorscheme.sh); or set -gx VIM_COLOR wombat256mod