Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support bat for syntax highlighting in preview #712

Merged
merged 3 commits into from
Nov 9, 2018

Conversation

wookayin
Copy link
Contributor

@wookayin wookayin commented Oct 7, 2018

bat is a very nice clone of cat that supports syntax highlighting feature. If bat is available, one may want to have it as a syntax highlighter used in preview.sh or preview.rb. This PR adds the support.

I have implemented the functionality to be close to what preview.sh is doing, with awk. Of course, the use of bat is absolutely optional. It allows us to have a syntax highlighting feature even without ruby.

image

Another note: it might conflict with #707.

@junegunn
Copy link
Owner

Thanks. Now with a few more changes, we no longer need the ruby version, right?

@wookayin
Copy link
Contributor Author

I agree with you that we can eventually remove the ruby script. One may still want to use highlight, coderay, or rougify, but as long as we are able to configure which highlighter is used (as well as a few more changes), the ruby one is not needed and therefore the previewer scripts can be unified into more general one.

For configuration points, let's discuss on #707 (comment).

@junegunn
Copy link
Owner

Trying out bat, highlight, ..., finally cat in turn should be good enough for most users. It works out of the box without any configuration, and that's a big plus from my perspective. It's a little hard for me to imagine that someone installed bat or highlight would still want to use slower – or less "modern" – alternatives like coderay or rougify. bat even checks BAT_THEME environment variable, so one can still customize its look even though we don't allow custom commands.

@felipesere
Copy link

This looks brilliant, what is missing for this to get merged? 😄

wookayin and others added 3 commits November 9, 2018 15:37
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
One can still take advantage of `bat` as a syntax highlighter,
when ruby is available but other ruby-based highlighter packages
are not installed.
- Use preview.sh instead of preview.rb by default
- Try bat syntax highlighter with the highest priority
- Remove "-v" option as the latest version of fzf sets up $LINES
- Allow users to customize the preview command via $FZF_PREVIEW_COMMAND
  - *EXPERIMENTAL / EVOLVING / UNDOCUMENTED*
  - Should be a command template with {} placeholder expression
    - e.g. "nl {}"
@junegunn junegunn merged commit 0dbcfb2 into junegunn:master Nov 9, 2018
@junegunn
Copy link
Owner

junegunn commented Nov 9, 2018

Made a few changes. Please see the commit message for details. Thanks.

@wookayin
Copy link
Contributor Author

wookayin commented Nov 9, 2018

Looks very good, thanks!

@wookayin wookayin deleted the feature/preview-bat branch November 11, 2018 08:38
junegunn pushed a commit to junegunn/fzf that referenced this pull request Mar 29, 2019
TylerSeanRau pushed a commit to TylerSeanRau/fzf that referenced this pull request May 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants