File tree 1 file changed +39
-1
lines changed
1 file changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,45 @@ __fzf_cd__() {
54
54
) && printf ' builtin cd -- %q' " $( builtin unset CDPATH && builtin cd -- " $dir " && builtin pwd) "
55
55
}
56
56
57
- if command -v perl > /dev/null; then
57
+ if command -v ruby > /dev/null; then
58
+ __fzf_history__ () {
59
+ local n output
60
+ builtin history -w /tmp/fzf-bash-history
61
+ output=$(
62
+ ruby -e '
63
+ fmt = begin
64
+ require "rouge"
65
+ formatter = Rouge::Formatters::Terminal256.new(Rouge::Themes::Monokai.new)
66
+ lexer = Rouge::Lexers::Shell.new
67
+ lambda { |c| formatter.format(lexer.lex(c)) }
68
+ rescue LoadError
69
+ lambda { |c| c }
70
+ end
71
+
72
+ h = {}
73
+ i = 0
74
+ File.read("/tmp/fzf-bash-history").scan(/^#([0-9]+)$\n(.*?)\n(?=^#[0-9]+$|\z)/m) do |t, c|
75
+ next if c.empty?
76
+ h.delete(c)
77
+ h[c] = [i += 1, t]
78
+ end
79
+ h.to_a.reverse.each do |c, it|
80
+ i, t = it
81
+ print "\x1b[33m#{i}\t\x1b[32m#{Time.at(t.to_i).strftime(%[%F %T])}\x1b[m "
82
+ print fmt[c.gsub("\n", "\n\t")]
83
+ print "\0"
84
+ end
85
+ ' | FZF_DEFAULT_OPTS=$( __fzf_defaults " " " -n1,4.. --ansi --scheme=history --bind=ctrl-r:toggle-sort --wrap-sign '" $' \t ' " ↳ ' --highlight-line ${FZF_CTRL_R_OPTS-} +m --read0" ) \
86
+ FZF_DEFAULT_OPTS_FILE=' ' $( __fzfcmd) --query " $READLINE_LINE " --bind ' enter:become:echo {4..}'
87
+ ) || return
88
+ READLINE_LINE=$( command perl -pe ' s/^\d*\t//' <<< " $output" )
89
+ if [[ -z " $READLINE_POINT " ]]; then
90
+ echo " $READLINE_LINE "
91
+ else
92
+ READLINE_POINT=0x7fffffff
93
+ fi
94
+ }
95
+ elif command -v perl > /dev/null; then
58
96
__fzf_history__ () {
59
97
local output script
60
98
script=' BEGIN { getc; $/ = "\n\t"; $HISTCOUNT = $ENV{last_hist} + 1 } s/^[ *]//; s/\n/\n\t/gm; print $HISTCOUNT - $. . "\t$_" if !$seen{$_}++'
You can’t perform that action at this time.
0 commit comments