mirror of
https://github.com/junegunn/fzf.vim.git
synced 2025-12-07 21:24:40 +08:00
Add preview.sh for ruby-less previews. (#259)
This commit is contained in:
@@ -29,7 +29,8 @@ set cpo&vim
|
|||||||
" ------------------------------------------------------------------
|
" ------------------------------------------------------------------
|
||||||
|
|
||||||
let s:layout_keys = ['window', 'up', 'down', 'left', 'right']
|
let s:layout_keys = ['window', 'up', 'down', 'left', 'right']
|
||||||
let s:bin = { 'preview': expand('<sfile>:h:h:h').'/bin/preview.rb' }
|
let s:which_bin = executable('ruby') ? '/bin/preview.rb' : '/bin/preview.sh'
|
||||||
|
let s:bin = { 'preview': expand('<sfile>:h:h:h') . s:which_bin }
|
||||||
let s:TYPE = {'dict': type({}), 'funcref': type(function('call')), 'string': type('')}
|
let s:TYPE = {'dict': type({}), 'funcref': type(function('call')), 'string': type('')}
|
||||||
|
|
||||||
" [[options to wrap], preview window expression, [toggle-preview keys...]]
|
" [[options to wrap], preview window expression, [toggle-preview keys...]]
|
||||||
@@ -55,10 +56,6 @@ function! fzf#vim#with_preview(...)
|
|||||||
call remove(args, 0)
|
call remove(args, 0)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !executable('ruby')
|
|
||||||
return options
|
|
||||||
endif
|
|
||||||
|
|
||||||
let preview = printf(' --preview-window %s --preview "%s"\ %s\ {}',
|
let preview = printf(' --preview-window %s --preview "%s"\ %s\ {}',
|
||||||
\ window,
|
\ window,
|
||||||
\ shellescape(s:bin.preview), window =~ 'up\|down' ? '-v' : '')
|
\ shellescape(s:bin.preview), window =~ 'up\|down' ? '-v' : '')
|
||||||
|
|||||||
44
bin/preview.sh
Executable file
44
bin/preview.sh
Executable file
@@ -0,0 +1,44 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
REVERSE="\x1b[7m"
|
||||||
|
RESET="\x1b[m"
|
||||||
|
|
||||||
|
if [ "$1" == "-v" ]; then
|
||||||
|
SPLIT=1
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
echo "usage: $0 [-v] FILENAME[:LINENO][:IGNORED]"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
IFS=':' read -r -a INPUT <<< "$1"
|
||||||
|
FILE=${INPUT[0]}
|
||||||
|
CENTER=${INPUT[1]}
|
||||||
|
|
||||||
|
if [ ! -r "$FILE" ]; then
|
||||||
|
echo "File not found ${FILE}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$CENTER" ]; then
|
||||||
|
CENTER=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -r /dev/tty ]; then
|
||||||
|
LINES=$(stty size < /dev/tty | awk '{print $1}')
|
||||||
|
else
|
||||||
|
LINES=40
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$SPLIT" ]; then
|
||||||
|
LINES=$(($LINES/2)) # using horizontal split
|
||||||
|
fi
|
||||||
|
LINES=$(($LINES-2)) # remove preview border
|
||||||
|
|
||||||
|
FIRST=$(($CENTER-$LINES/3))
|
||||||
|
FIRST=$(($FIRST < 1 ? 1 : $FIRST))
|
||||||
|
LAST=$((${FIRST}+${LINES}-1))
|
||||||
|
|
||||||
|
awk "NR >= $FIRST && NR <= $LAST {if (NR == $CENTER) printf(\"\x1b[7m%5d %s\n\x1b[m\", NR, \$0); else printf(\"%5d %s\n\", NR, \$0)}" $FILE
|
||||||
Reference in New Issue
Block a user