fzf-completion.bash (2377B)
1 # ble/contrib/integration/fzf-completion.bash (C) 2020-2023, akinomyoga 2 3 ble-import contrib/integration/fzf-initialize 4 5 [[ $- == *i* ]] || return 0 6 7 # fzf/shell/completion.bash を未ロードの時のみロードする 8 if ! ble/is-function _fzf_complete; then 9 if [[ -f $_ble_contrib_fzf_base/completion.bash ]]; then 10 source "$_ble_contrib_fzf_base/completion.bash" 11 elif [[ -f $_ble_contrib_fzf_base/shell/completion.bash ]]; then 12 source "$_ble_contrib_fzf_base/shell/completion.bash" 13 elif [[ $_ble_contrib_fzf_base == */share/fzf && -f /etc/bash_completion.d/fzf ]]; then 14 source /etc/bash_completion.d/fzf 15 fi 16 fi 17 18 # clear blesh completer for cd 19 blehook/eval-after-load complete 'unset -f ble/cmdinfo/complete:cd' 20 21 # patch fzf functions 22 ble/function#advice around __fzf_generic_path_completion _fzf_complete.advice 23 ble/function#advice around _fzf_complete _fzf_complete.advice 24 ble/function#advice around _fzf_complete_kill _fzf_complete.advice 25 function _fzf_complete.advice { 26 if [[ ! ${_ble_attached-} ]]; then 27 ble/function#push caller 'builtin caller ${1+"$(($1+6))"}' 28 ble/function#advice/do 29 ble/function#pop caller 30 return 0 31 fi 32 33 [[ :$comp_type: == *:auto:* || :$comp_type: == *:[maA]:* ]] && return 0 34 compopt -o ble/syntax-raw 35 if [[ ! ${_ble_contrib_fzf_comp_words_raw-} ]]; then 36 local _ble_contrib_fzf_comp_words_raw=1 37 local COMP_WORDS; COMP_WORDS=("${comp_words[@]}") 38 local COMP_CWORD=$comp_cword 39 local COMP_LINE=$comp_line COMP_POINT=$comp_point 40 fi 41 ble/function#push printf '[[ $1 == "\e[5n" ]] || builtin printf "$@"' 42 ble/function#push caller 'builtin caller ${1+"$(($1+6))"}' 43 ble/term/leave-for-widget 44 if [[ ${ADVICE_WORDS[0]} == _fzf_complete ]]; then 45 ble/function#advice/do >&"$_ble_util_fd_stdout" 2>&"$_ble_util_fd_stderr" 46 else 47 ble/function#advice/do >&"$_ble_util_fd_stdout" 2>&"$_ble_util_fd_stderr" <&"$_ble_util_fd_stdin" 48 fi 49 ble/term/enter-for-widget 50 ble/function#pop caller 51 ble/function#pop printf 52 ble/textarea#invalidate 53 54 # 単一候補生成の場合は他の候補 (sabbrev 等) を消去して単一確定させる 55 if ((ADVICE_EXIT==0&&${#COMPREPLY[@]}==1)); then 56 compopt -o ble/no-default 57 ble/complete/candidates/clear 58 [[ $old_cand_count ]] && 59 ! ble/variable#is-global old_cand_count && 60 old_cand_count=0 61 fi 62 }