-
Notifications
You must be signed in to change notification settings - Fork 1
/
fzf.zsh
45 lines (39 loc) · 1.33 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
33
34
35
36
37
38
39
40
41
42
43
44
45
# Setup fzf (handle various environments)
if [[ -a "/opt/homebrew/opt/fzf" ]]; then
# OS X
FZF_SHELL_PATH="/opt/homebrew/opt/fzf/shell"
FZF_BIN_PATH="/opt/homebrew/opt/fzf/bin"
elif [[ -a "/usr/share/fzf" ]]; then
# Linux
FZF_SHELL_PATH="/usr/share/fzf"
# FZF_BIN_PATH not necessary since it'll be in /usr[/local]/bin
elif [[ -a "$HOME/.fzf" ]]; then
# Git install
FZF_SHELL_PATH="$HOME/.fzf/shell"
FZF_BIN_PATH="$HOME/.fzf/bin"
else
# Could not locate fzf install, nothing to do here
return
fi
# $PATH
# If fzf is not already found in $PATH, check to see if it's because $FZF_BIN_PATH is missing from $PATH, and add it if so
type fzf &>/dev/null || if [[ ! "$PATH" == *"$FZF_BIN_PATH"* ]]; then
export PATH="${PATH:+${PATH}:}$FZF_BIN_PATH"
fi
# Confirm that it's loaded
type fzf &>/dev/null || { echo "Could not locate fzf" && return ; }
# Auto-completion
[[ $- == *i* ]] && source "$FZF_SHELL_PATH/completion.zsh" 2> /dev/null
# Key bindings
source "$FZF_SHELL_PATH/key-bindings.zsh"
# Use rg wherever possible
type rg &>/dev/null || return
export FZF_DEFAULT_COMMAND='rg --files --hidden --follow'
_fzf_compgen_path() {
rg --hidden --files "$1" 2>/dev/null | with-dir "$1"
}
_fzf_compgen_dir() {
rg --hidden --files "$1" 2>/dev/null | only-dir "$1"
}
# Add C-g C-* key bindings for git completions
source ~/.oh-my-zsh/custom/.fzf.git.zsh