1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# vim: ft=zsh :
export FZF_DEFAULT_OPTS="--color=light"
if [ $(command -v fdfind) ] ; then
export FZF_DEFAULT_COMMAND="fdfind --type file"
export FZF_ALT_C_COMMAND="fdfind --type directory"
elif [ $(command -v fd) ] ; then
export FZF_DEFAULT_COMMAND="fd --type file"
export FZF_ALT_C_COMMAND="fd --type directory"
fi
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
[ -f /usr/share/doc/fzf/examples/key-bindings.zsh ] && source /usr/share/doc/fzf/examples/key-bindings.zsh
[ -f /usr/share/doc/fzf/examples/completion.zsh ] && source /usr/share/doc/fzf/examples/completion.zsh
# https://github.com/junegunn/fzf/wiki/Color-schemes
_gen_fzf_default_opts() {
local base03="234"
local base02="235"
local base01="240"
local base00="241"
local base0="244"
local base1="245"
local base2="254"
local base3="230"
local yellow="136"
local orange="166"
local red="160"
local magenta="125"
local violet="61"
local blue="33"
local cyan="37"
local green="64"
# Comment and uncomment below for the light theme.
# Solarized Dark color scheme for fzf
#export FZF_DEFAULT_OPTS="
# --color fg:-1,bg:-1,hl:$blue,fg+:$base2,bg+:$base02,hl+:$blue
# --color info:$yellow,prompt:$yellow,pointer:$base3,marker:$base3,spinner:$yellow
#"
## Solarized Light color scheme for fzf
export FZF_DEFAULT_OPTS="
--color fg:-1,bg:-1,hl:$blue,fg+:$base02,bg+:$base2,hl+:$blue
--color info:$yellow,prompt:$yellow,pointer:$base03,marker:$base03,spinner:$yellow
"
}
_gen_fzf_default_opts
#
# https://github.com/junegunn/fzf/discussions/3629
#
modified-fzf-history-widget() {
local selected
setopt localoptions noglobsubst noposixbuiltins pipefail no_aliases no_bash_rematch 2> /dev/null
# appends the current shell history buffer to the HISTFILE
builtin fc -AI $HISTFILE
# pushes entries from the $HISTFILE onto a stack and uses this history
builtin fc -p $HISTFILE $HISTSIZE $SAVEHIST
selected="$(builtin fc -rl 1 |
awk '{ cmd=$0; sub(/^[ \t]*[0-9]+\**[ \t]+/, "", cmd); if (!seen[cmd]++) print $0 }' |
FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} ${FZF_DEFAULT_OPTS-} -n2..,.. --scheme=history --bind=ctrl-r:toggle-sort,ctrl-z:ignore ${FZF_CTRL_R_OPTS-} --query=${(qqq)LBUFFER} --multi" $(__fzfcmd))"
local ret=$?
if [[ -n $selected ]]; then
if [[ "$selected" =~ ^[[:blank:]]*[[:digit:]]+ ]]; then
builtin fc -pa "$HISTFILE"
zle vi-fetch-history -n "$MATCH"
else # selected is a custom query, not from history
LBUFFER="$selected"
fi
fi
# Read the history from the history file into the history list
builtin fc -R $HISTFILE
zle reset-prompt
return $ret
}
zle -N modified-fzf-history-widget
bindkey "^R" modified-fzf-history-widget
export FZF_CTRL_R_OPTS="$(
cat <<'FZF_FTW'
--bind "ctrl-d:execute-silent(zsh -ic 'builtin fc -p $HISTFILE $HISTSIZE $SAVEHIST; for i in {+1}; do ignore+=( \"${(b)history[$i]}\" );done;
HISTORY_IGNORE=\"(${(j:|:)ignore})\";builtin fc -W $HISTFILE')+reload:builtin fc -p $HISTFILE $HISTSIZE $SAVEHIST; builtin fc -rl 1 |
awk '{ cmd=$0; sub(/^[ \t]*[0-9]+\**[ \t]+/, \"\", cmd); if (!seen[cmd]++) print $0 }'"
--bind 'enter:accept-or-print-query'
--header 'enter select · ^d remove'
--prompt ' Global History > '
FZF_FTW
)"
_setup_fzf_ctrl_t_options() {
#
# fzf Ctrl+T options
# https://github.com/junegunn/fzf#key-bindings-for-command-line
#
local preview_command
if command -v bat >/dev/null 2>&1; then
preview_command="bat --color=always --line-range :500"
else
preview_command="cat"
fi
local find_command
if [ $(command -v fdfind) ] ; then
find_command="fdfind --type file --hidden"
elif [ $(command -v fd) ] ; then
find_command="fd --type file --hidden"
fi
FZF_CTRL_T_OPTS="${FZF_CTRL_T_OPTS:-} --preview '$preview_command {}'"
FZF_CTRL_T_OPTS="${FZF_CTRL_T_OPTS} --bind 'ctrl-/:change-preview-window(down|hidden|)'"
FZF_CTRL_T_OPTS="${FZF_CTRL_T_OPTS} --bind 'ctrl-v:become(\"${EDITOR:-vim}\" -- {+} </dev/tty >/dev/tty)'"
FZF_CTRL_T_OPTS="${FZF_CTRL_T_OPTS} --bind 'ctrl-a:reload($find_command),ctrl-h:reload(eval \"${FZF_DEFAULT_COMMAND}\")'"
FZF_CTRL_T_OPTS="${FZF_CTRL_T_OPTS} --header 'enter select · ^/ toggle preview · ^v edit · ^(a|h) toggle hidden'"
export FZF_CTRL_T_OPTS
}
_setup_fzf_ctrl_t_options
unfunction _setup_fzf_ctrl_t_options
|