diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2018-09-10 10:50:45 -0600 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2018-09-10 10:50:45 -0600 |
commit | 5ece6ef2f07c58672a9c965dbbbb62a42386fb2d (patch) | |
tree | 285e6382f9e900779bce60da02f1f0d97e467e26 /plugins/fzf | |
parent | 852e7fe005267f74f3c04a4ddbb310522eee8014 (diff) | |
parent | fe5fe81c8cfa66981c51d149a35fe545f2ef5016 (diff) | |
download | zsh-5ece6ef2f07c58672a9c965dbbbb62a42386fb2d.tar.gz zsh-5ece6ef2f07c58672a9c965dbbbb62a42386fb2d.tar.bz2 zsh-5ece6ef2f07c58672a9c965dbbbb62a42386fb2d.zip |
Merge branch 'master' of https://github.com/robbyrussell/oh-my-zsh
Diffstat (limited to 'plugins/fzf')
-rw-r--r-- | plugins/fzf/README.md | 19 | ||||
-rw-r--r-- | plugins/fzf/fzf.plugin.zsh | 57 |
2 files changed, 76 insertions, 0 deletions
diff --git a/plugins/fzf/README.md b/plugins/fzf/README.md new file mode 100644 index 000000000..b3a434347 --- /dev/null +++ b/plugins/fzf/README.md @@ -0,0 +1,19 @@ +# fzf + +This plugin enables [junegunn's fzf](https://github.com/junegunn/fzf) fuzzy auto-completion and key bindings + +```zsh +# Set fzf installation directory path +export FZF_BASE=/path/to/fzf/install/dir + +# Uncomment the following line to disable fuzzy completion +# export DISABLE_FZF_AUTO_COMPLETION="true" + +# Uncomment the following line to disable key bindings (CTRL-T, CTRL-R, ALT-C) +# export DISABLE_FZF_KEY_BINDINGS="true" + +plugins=( + ... + fzf +) +``` diff --git a/plugins/fzf/fzf.plugin.zsh b/plugins/fzf/fzf.plugin.zsh new file mode 100644 index 000000000..27e2d9246 --- /dev/null +++ b/plugins/fzf/fzf.plugin.zsh @@ -0,0 +1,57 @@ +test -d "${FZF_BASE}" && fzf_base="${FZF_BASE}" + +if [[ -z "${fzf_base}" ]]; then + fzfdirs=( + "${HOME}/.fzf" + "/usr/local/opt/fzf" + "/usr/share/fzf" + ) + for dir in ${fzfdirs}; do + if [[ -d "${dir}" ]]; then + fzf_base="${dir}" + break + fi + done + + if [[ -z "${fzf_base}" ]]; then + if (( ${+commands[brew]} )) && dir="$(brew --prefix fzf 2>/dev/null)"; then + if [[ -d "${dir}" ]]; then + fzf_base="${dir}" + fi + fi + fi +fi + +if [[ -n "${fzf_base}" ]]; then + + # Fix fzf shell directory for Archlinux package + if [[ ! -d "${fzf_base}/shell" ]] && [[ -f /etc/arch-release ]]; then + fzf_shell="${fzf_base}" + else + fzf_shell="${fzf_base}/shell" + fi + + # Setup fzf + # --------- + if ! (( ${+commands[fzf]} )) && [[ ! "$PATH" == *$fzf_base/bin* ]]; then + export PATH="$PATH:$fzf_base/bin" + fi + + # Auto-completion + # --------------- + if [[ ! "$DISABLE_FZF_AUTO_COMPLETION" == "true" ]]; then + [[ $- == *i* ]] && source "${fzf_shell}/completion.zsh" 2> /dev/null + fi + + # Key bindings + # ------------ + if [[ ! "$DISABLE_FZF_KEY_BINDINGS" == "true" ]]; then + source "${fzf_shell}/key-bindings.zsh" + fi + +else + print "[oh-my-zsh] fzf plugin: Cannot find fzf installation directory.\n"\ + "Please add \`export FZF_BASE=/path/to/fzf/install/dir\` to your .zshrc" >&2 +fi + +unset fzf_base fzf_shell dir fzfdirs |