-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathfzf-config
126 lines (115 loc) · 4.13 KB
/
fzf-config
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
120
121
122
123
124
125
126
#!/usr/bin/env zsh
# Set PATH
if [[ ! "$PATH" == */Users/rockyzhang/gitrepos/fzf/bin* ]]; then
PATH="${PATH:+${PATH}:}/Users/rockyzhang/gitrepos/fzf/bin"
fi
# Enable auto-completion and keybindings
eval "$(fzf --zsh)"
# Default fd command
FD="fd --hidden --follow $FD_EXCLUDE"
# Use fd instead of default find
export FZF_DEFAULT_COMMAND="$FD --type f"
# Define color themes
# Default colors are defined in https://github.com/junegunn/fzf/blob/master/src/tui/tui.go
if $TRANSPARENT; then
bg=-1
fi
# arctic theme
if [[ $COLOR_THEME == 'arctic' ]]; then
[[ $bg != -1 ]] && bg='#1f1f1f'
fg='#cccccc'
colors="dark,fg:$fg,bg:$bg,hl:#2aaaff:bold,fg+:#ffffff,bg+:#04395e,gutter:$bg,hl+:#2aaaff:bold,query:$fg,disabled:#808080,border:$fg,separator:#454545,label:$fg,header:#3794ff:underline"
fi
# monokai theme
if [[ $COLOR_THEME == 'monokai' ]]; then
[[ $bg != -1 ]] && bg='#272822'
fg='#f8f8f2'
colors="dark,fg:$fg,bg:$bg,hl:#ffdd33:bold,fg+:#ffffff,bg+:#414339,gutter:$bg,hl+:#ffdd33:bold,query:$fg,disabled:#7a7a77,border:$fg,separator:#454545,label:$fg,header:#fd9621:underline:bold"
fi
# Config the default options when running fzf
# Keybindings:
# - ctrl-d: move cursor half page down
# - ctrl-u: move cursor halp page up
# - alt-d: move preview half page down
# - alt-u: move preview half page up
# - ctrl-a: toggle all
# - ctrl-s: toggle single
# - ctrl-/: toggle preview window
# - ctrl-w: toggle wrap
# - alt-w: toggle preview wrap
# - ctrl-o: open the selections via default application
# - ctrl-y: copy the selections to system clipboard
# - ctrl-e: edit the selections via $EDITOR
export FZF_DEFAULT_OPTS=" \
--reverse \
--height 85% \
--multi \
--no-mouse \
--scrollbar '█' \
--history /tmp/fzfhistory \
--prompt 'FZF> ' \
--border rounded \
--tabstop=4 \
--highlight-line \
--tmux 80%,85% \
--bind 'ctrl-d:half-page-down,ctrl-u:half-page-up,alt-d:preview-half-page-down,`
`alt-u:preview-half-page-up,ctrl-a:toggle-all,`
`ctrl-/:toggle-preview,`
`ctrl-w:toggle-wrap,`
`alt-w:toggle-preview-wrap,`
`ctrl-s:toggle,`
`ctrl-o:execute(open {+}),`
`ctrl-y:execute-silent(echo -n {+} | pbcopy),`
`ctrl-e:execute(\$EDITOR {+} < /dev/tty > /dev/tty 2>&1),`
`change:first' \
--bind 'focus:transform-preview-label:echo [ {} ]' \
--preview '~/.config/fzf/fzf-previewer.sh {}' \
--preview-window 'right,60%' \
--color=$colors"
# Use fd for FZF completion
# 1). listing files and dirs ($1 is the base path to start search) such as "vim ~/.config/**<TAB>"
_fzf_compgen_path() {
fd --hidden --follow ${(z)FD_EXCLUDE} . "$1"
}
# 2). listing dirs such as "cd **<TAB>"
_fzf_compgen_dir() {
fd --type d --hidden --follow ${(z)FD_EXCLUDE} . "$1"
}
# CTRL-T to paste the selected files and directories onto the command-line
export FZF_CTRL_T_COMMAND="$FD"
export FZF_CTRL_T_OPTS=" \
--prompt 'Dirs [current]> ' \
--header ':: CTRL-H (home), CTRL-R (root), CTRL-C (current)' \
--bind 'ctrl-h:reload($FD . $HOME)+change-prompt(Dirs [home]> )' \
--bind 'ctrl-r:reload($FD . /)+change-prompt(Dirs [root]> )' \
--bind 'ctrl-c:reload($FD)+change-prompt(Dirs [current]> )' \
"
# CTRL-R to search the command history
export FZF_CTRL_R_OPTS=" \
--prompt 'Command History> ' \
--preview 'echo {}' \
--bind 'ctrl-y:execute-silent(echo -n {2..} | pbcopy)' \
--header ':: CTRL-Y (copy to clipboard)'"
# CTRL-J to cd into the selected dir
# - ALT-P: show parent dirs
# - ALT-S: show sub dirs
bindkey '^j' fzf-cd-widget
export FZF_ALT_C_COMMAND="$FD --type d"
export FZF_ALT_C_OPTS=" \
--preview 'tree -C {} | head -200' \
--header ':: ALT-P (show parent dirs)' \
--prompt 'SubDirs> ' \
--bind 'alt-p:reload(print-parent-dirs)+change-header(:: ALT-S (show subdirs))+change-prompt(ParentDirs> )' \
--bind 'alt-s:reload($FZF_ALT_C_COMMAND)+change-header(:: ALT-P (show parent dirs))+change-prompt(SubDirs> )'"
# fzf + git
# Reference: https://github.com/junegunn/fzf-git.sh
# CTRL-G F for files
# CTRL-G B for branches
# CTRL-G T for tags
# CTRL-G R for remotes
# CTRL-G H for commit hashes
# CTRL-G S for stashes
# CTRL-G L for Reflogs
# CTRL-G E for Each ref (git for-each-ref)
# CTRL-G W for Worktrees
source ~/.config/fzf/fzf-git.sh