From b73d141b749ed49e146a5c6862cb79467ecbd53d Mon Sep 17 00:00:00 2001 From: Jongwook Choi Date: Sun, 7 Oct 2018 16:27:53 -0400 Subject: [PATCH] [preview] Support bat for syntax highlighting in preview.rb One can still take advantage of `bat` as a syntax highlighter, when ruby is available but other ruby-based highlighter packages are not installed. --- README.md | 1 + bin/preview.rb | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0a80b00..c57e216 100644 --- a/README.md +++ b/README.md @@ -188,6 +188,7 @@ command! -bang Colors " - Highlight: http://www.andre-simon.de/doku/highlight/en/highlight.php " - CodeRay: http://coderay.rubychan.de/ " - Rouge: https://github.com/jneen/rouge +" - Bat: https://github.com/sharkdp/bat " " :Ag - Start fzf with hidden preview window that can be enabled with "?" key " :Ag! - Start fzf in fullscreen and display the preview window above diff --git a/bin/preview.rb b/bin/preview.rb index d33730a..62a320c 100755 --- a/bin/preview.rb +++ b/bin/preview.rb @@ -4,7 +4,7 @@ require 'shellwords' -COMMAND = %[(highlight -O ansi -l {} || coderay {} || rougify {} || cat {}) 2> /dev/null] +COMMAND = %[(highlight -O ansi -l {} || coderay {} || rougify {} || bat --style=numbers --color=always {} || cat {}) 2> /dev/null] ANSI = /\x1b\[[0-9;]*m/ REVERSE = "\x1b[7m" RESET = "\x1b[m" @@ -55,3 +55,4 @@ IO.popen(['sh', '-c', COMMAND.gsub('{}', Shellwords.shellescape(path))]) do |io| end end end +print RESET