From e74b1251c0f579335e03b3e7182cd7a9f88dbe37 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Wed, 13 Mar 2024 23:59:34 +0900 Subject: Embed shell integration scripts in fzf binary (`--bash` / `--zsh` / `--fish`) (#3675) This simplifies the distribution, and the users are less likely to have problems caused by using incompatible scripts and binaries. # Set up fzf key bindings and fuzzy completion eval "$(fzf --bash)" # Set up fzf key bindings and fuzzy completion eval "$(fzf --zsh)" # Set up fzf key bindings fzf --fish | source --- install | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'install') diff --git a/install b/install index e790b749..22a0c0be 100755 --- a/install +++ b/install @@ -262,6 +262,12 @@ if [[ ! "\$PATH" == *$fzf_base_esc/bin* ]]; then PATH="\${PATH:+\${PATH}:}$fzf_base/bin" fi +EOF + + if [[ $auto_completion -eq 1 ]] && [[ $key_bindings -eq 1 ]]; then + echo "eval \"\$(fzf --$shell)\"" >> "$src" + else + cat >> "$src" << EOF # Auto-completion # --------------- $fzf_completion @@ -270,6 +276,7 @@ $fzf_completion # ------------ $fzf_key_bindings EOF + fi echo "OK" done @@ -281,18 +288,6 @@ if [[ "$shells" =~ fish ]]; then or set --universal fish_user_paths \$fish_user_paths "$fzf_base"/bin EOF [ $? -eq 0 ] && echo "OK" || echo "Failed" - - mkdir -p "${fish_dir}/functions" - fish_binding="${fish_dir}/functions/fzf_key_bindings.fish" - if [ $key_bindings -ne 0 ]; then - echo -n "Symlink $fish_binding ... " - ln -sf "$fzf_base/shell/key-bindings.fish" \ - "$fish_binding" && echo "OK" || echo "Failed" - else - echo -n "Removing $fish_binding ... " - rm -f "$fish_binding" - echo "OK" - fi fi append_line() { @@ -355,12 +350,23 @@ done if [ $key_bindings -eq 1 ] && [[ "$shells" =~ fish ]]; then bind_file="${fish_dir}/functions/fish_user_key_bindings.fish" if [ ! -e "$bind_file" ]; then + mkdir -p "${fish_dir}/functions" create_file "$bind_file" \ 'function fish_user_key_bindings' \ - ' fzf_key_bindings' \ + ' fzf --fish | source' \ 'end' else - append_line $update_config "fzf_key_bindings" "$bind_file" + echo "Check $bind_file:" + lno=$(\grep -nF "fzf_key_bindings" "$bind_file" | sed 's/:.*//' | tr '\n' ' ') + if [[ -n $lno ]]; then + echo " ** Found 'fzf_key_bindings' in line #$lno" + echo " ** You have to replace the line to 'fzf --fish | source'" + echo + else + echo " - Clear" + echo + append_line $update_config "fzf --fish | source" "$bind_file" + fi fi fi -- cgit v1.2.3