mirror of
https://github.com/junegunn/fzf.vim.git
synced 2025-12-07 21:24:40 +08:00
[preview] Use bat for syntax highlighting if available
In the preview.sh script (used when ruby is not installed), `bat` (a clone of `cat` with syntax highlighting, etc.) can be used for the sake of syntax highlighting. If bat is not available, just fallback to the plain cat as before. [bat]: https://github.com/sharkdp/bat
This commit is contained in:
committed by
Junegunn Choi
parent
50707b089b
commit
974d366b33
@@ -52,4 +52,16 @@ FIRST=$(($CENTER-$LINES/3))
|
|||||||
FIRST=$(($FIRST < 1 ? 1 : $FIRST))
|
FIRST=$(($FIRST < 1 ? 1 : $FIRST))
|
||||||
LAST=$((${FIRST}+${LINES}-1))
|
LAST=$((${FIRST}+${LINES}-1))
|
||||||
|
|
||||||
awk "NR >= $FIRST && NR <= $LAST {if (NR == $CENTER) printf(\"$REVERSE%5d %s\n$RESET\", NR, \$0); else printf(\"%5d %s\n\", NR, \$0)}" $FILE
|
if which bat >/dev/null; then
|
||||||
|
CAT="bat --style=numbers --color=always"
|
||||||
|
$CAT $FILE | awk "NR >= $FIRST && NR <= $LAST { \
|
||||||
|
if (NR == $CENTER) \
|
||||||
|
{ gsub(/\x1b[[0-9;]*m/, \"&$REVERSE\"); printf(\"$REVERSE%s\n$RESET\", \$0); } \
|
||||||
|
else printf(\"$RESET%s\n\", \$0); \
|
||||||
|
}"
|
||||||
|
else
|
||||||
|
awk "NR >= $FIRST && NR <= $LAST { \
|
||||||
|
if (NR == $CENTER) printf(\"$REVERSE%5d %s\n$RESET\", NR, \$0); \
|
||||||
|
else printf(\"%5d %s\n\", NR, \$0); \
|
||||||
|
}" $FILE
|
||||||
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user