From 1544056ab91c5070cdef4a389e9847e4ebbec350 Mon Sep 17 00:00:00 2001 From: Tom Hicks Date: Mon, 7 Sep 2026 17:48:28 -0700 Subject: [PATCH] Makes fzf availalbe in other shells. --- .rc.d/fzf.sh | 76 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 62 insertions(+), 14 deletions(-) diff --git a/.rc.d/fzf.sh b/.rc.d/fzf.sh index c8b2aa7..e689a36 100755 --- a/.rc.d/fzf.sh +++ b/.rc.d/fzf.sh @@ -1,16 +1,64 @@ -# To set up shell integration, add this to your shell configuration file: -# # bash -# eval "$(fzf --bash)" +# Setup fzf shell integration (bash, zsh, and fallback paths) +_setup_fzf() { + # Ensure fzf binary is accessible if installed in common locations + if ! command -v fzf >/dev/null 2>&1; then + for _fzf_bin_dir in \ + "/opt/homebrew/bin" \ + "/usr/local/bin" \ + "$HOME/.fzf/bin" \ + "$HOME/.local/bin" + do + if [ -x "$_fzf_bin_dir/fzf" ]; then + case ":$PATH:" in + *":$_fzf_bin_dir:"*) ;; + *) PATH="$_fzf_bin_dir:$PATH"; export PATH ;; + esac + break + fi + done + fi -# # zsh -# source <(fzf --zsh) + command -v fzf >/dev/null 2>&1 || return 0 -# # fish -# fzf --fish | source - -# To use fzf in Vim, add the following line to your .vimrc: -# set rtp+=/opt/homebrew/opt/fzf - -if [ -x "$(which fzf)" ]; then - source <(fzf --zsh) -fi + if [ -n "$BASH_VERSION" ]; then + if fzf --bash >/dev/null 2>&1; then + eval "$(fzf --bash)" + else + # Fallback for older fzf versions + for _dir in \ + "/opt/homebrew/opt/fzf/shell" \ + "/usr/local/opt/fzf/shell" \ + "$HOME/.fzf/shell" \ + "/usr/share/doc/fzf/examples" \ + "/usr/share/fzf" + do + if [ -d "$_dir" ]; then + [ -r "$_dir/completion.bash" ] && \. "$_dir/completion.bash" + [ -r "$_dir/key-bindings.bash" ] && \. "$_dir/key-bindings.bash" + break + fi + done + fi + elif [ -n "$ZSH_VERSION" ]; then + if fzf --zsh >/dev/null 2>&1; then + eval "$(fzf --zsh)" + else + # Fallback for older fzf versions + for _dir in \ + "/opt/homebrew/opt/fzf/shell" \ + "/usr/local/opt/fzf/shell" \ + "$HOME/.fzf/shell" \ + "/usr/share/doc/fzf/examples" \ + "/usr/share/fzf" + do + if [ -d "$_dir" ]; then + [ -r "$_dir/completion.zsh" ] && \. "$_dir/completion.zsh" + [ -r "$_dir/key-bindings.zsh" ] && \. "$_dir/key-bindings.zsh" + break + fi + done + fi + fi +} +_setup_fzf +unset -f _setup_fzf