-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfzf.zsh
32 lines (27 loc) · 1.1 KB
/
fzf.zsh
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
# Setup fzf
# ---------
if [[ ! "$PATH" == */opt/homebrew/opt/fzf/bin* ]]; then
export PATH="${PATH:+${PATH}:}/opt/homebrew/opt/fzf/bin"
fi
# Auto-completion
# ---------------
[[ $- == *i* ]] && source "/opt/homebrew/opt/fzf/shell/completion.zsh" 2> /dev/null
# Key bindings
# ------------
source "/opt/homebrew/opt/fzf/shell/key-bindings.zsh"
# Custom fuzzy completion
# ------------
# Bazel query (bzq alias)
# e.g. bzb **<TAB> or bzb DIRECTORY **<TAB> to show only targets of a given subdir
_fzf_complete_bzb() {
# Split the arguments into an array and assign the second word as query_subdir to filter on that specific subdir
local -a args
IFS=' ' read -A args <<< "$@"
# Note that this assumes the usage of bzb and not "bazel build", since it consider the 2nd argument to be the subdir
query_subdir="${args[2]}"
# Note that we do not restore the entire args but we drop the query_subdir (will be substituted by the fzf selection)
_fzf_complete --multi --reverse -- "${args[1]} " < <(\
bzq_cmd="bazel query ${query_subdir}/... --keep_going --noshow_progress"
eval "$bzq_cmd"
)
}