parent
8ffd3fb0ba
commit
d99169da2d
2 changed files with 24 additions and 17 deletions
|
@ -33,9 +33,13 @@ if `file --mime "#{file}"` =~ /binary/
|
|||
end
|
||||
|
||||
center = (center || 0).to_i
|
||||
height = File.readable?('/dev/tty') ? `stty size < /dev/tty`.split.first.to_i : 40
|
||||
height /= 2 if split
|
||||
height -= 2 # preview border
|
||||
if ENV['FZF_PREVIEW_HEIGHT']
|
||||
height = ENV['FZF_PREVIEW_HEIGHT'].to_i
|
||||
else
|
||||
height = File.readable?('/dev/tty') ? `stty size < /dev/tty`.split.first.to_i : 40
|
||||
height /= 2 if split
|
||||
height -= 2 # preview border
|
||||
end
|
||||
offset = [1, center - height / 3].max
|
||||
|
||||
IO.popen(['sh', '-c', COMMAND.gsub('{}', Shellwords.shellescape(path))]) do |io|
|
||||
|
|
|
@ -4,13 +4,13 @@ REVERSE="\x1b[7m"
|
|||
RESET="\x1b[m"
|
||||
|
||||
if [ "$1" == "-v" ]; then
|
||||
SPLIT=1
|
||||
shift
|
||||
SPLIT=1
|
||||
shift
|
||||
fi
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
echo "usage: $0 [-v] FILENAME[:LINENO][:IGNORED]"
|
||||
exit 1
|
||||
echo "usage: $0 [-v] FILENAME[:LINENO][:IGNORED]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
IFS=':' read -r -a INPUT <<< "$1"
|
||||
|
@ -18,8 +18,8 @@ FILE=${INPUT[0]}
|
|||
CENTER=${INPUT[1]}
|
||||
|
||||
if [ ! -r "$FILE" ]; then
|
||||
echo "File not found ${FILE}"
|
||||
exit 1
|
||||
echo "File not found ${FILE}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$(file --mime "$FILE")" =~ binary ]]; then
|
||||
|
@ -28,22 +28,25 @@ if [[ "$(file --mime "$FILE")" =~ binary ]]; then
|
|||
fi
|
||||
|
||||
if [ -z "$CENTER" ]; then
|
||||
CENTER=1
|
||||
CENTER=1
|
||||
fi
|
||||
|
||||
if [ -r /dev/tty ]; then
|
||||
LINES=$(stty size < /dev/tty | awk '{print $1}')
|
||||
if [ -n "$FZF_PREVIEW_HEIGHT" ]; then
|
||||
LINES=$FZF_PREVIEW_HEIGHT
|
||||
else
|
||||
if [ -r /dev/tty ]; then
|
||||
LINES=$(stty size < /dev/tty | awk '{print $1}')
|
||||
else
|
||||
LINES=40
|
||||
fi
|
||||
|
||||
if [ -n "$SPLIT" ]; then
|
||||
fi
|
||||
if [ -n "$SPLIT" ]; then
|
||||
LINES=$(($LINES/2)) # using horizontal split
|
||||
fi
|
||||
LINES=$(($LINES-2)) # remove preview border
|
||||
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
|
||||
awk "NR >= $FIRST && NR <= $LAST {if (NR == $CENTER) printf(\"$REVERSE%5d %s\n$RESET\", NR, \$0); else printf(\"%5d %s\n\", NR, \$0)}" $FILE
|
||||
|
|
Loading…
Add table
Reference in a new issue