CTRL-R: Show timestamp and syntax highlighted command#3936
CTRL-R: Show timestamp and syntax highlighted command#3936
Conversation
Formatter program in compiled languagesGolangI wrote a Go version of the Ruby code using Chroma library. However, the performance is worse than the Ruby version. RustI'm not familiar with Rust ecosystem, but trishume/syntect seems to be the most popular choice for syntax highlighting. However, according to the doc,
but the file I tested with is 11MBs, so we can't expect stellar performance. bat is known to use the library, so let's see. So, nope. |
04a1314 to
e8a39ee
Compare
|
Hi, is there any (option or hack?) way to get syntax highlighting only for the cursor line? I would be perfectly content with something like |
|
What I do is have a preview that highlights the line with bat. --preview='echo -n {2..} | bat -l bash -p --color=always --theme 1337' it's not perfect, but helps when I need the highlighting. Highlighting also affects readability, since fzf's search match colors are harder to visualize. I also have the following set, but it doesn't work as expected :) |
Close #1049
Close #3836
This is a proof-of-concept implementation of enhanced CTRL-R binding for bash.
Screenshot
Technicals
HISTTIMEFORMAT performance
For some reason,
$HISTTIMEFORMATmakes pipinghistoryextremely slow. Strangely, there is no slowdown when redirecting the output to another file.So we can work around this performance problem by writing it to a temp file and then reading it. But...
Syntax-highlighting of each command
We need to syntax-highlight each command, however, it's not viable to execute an external process such as
batfor each command.It's much faster to pass the whole file to
batat once,bat --style=plain --no-pager --language=bash ~/.bash_historyHowever, syntax-highlighting quickly breaks down due to malformed commands in history.
Complexity of the code
The Perl and Awk scripts for de-duplicating the list and handling multi-line commands are already quite complex and not easy to read and maintain. Adding timestamp and syntax-highlighting support to them would bring too much complexity.
Solution
I used a Ruby script to implement the enhanced CTRL-R binding. rouge gem was used for syntax-highlighting. The code isn't short, but I'd argue that it's still more readable.
Drawbacks
rougegem required for syntax-highlighting.Alternatives
TODO