sistema_progs

Programas para customizar o meu entorno de traballo nos meus equipos persoais
Log | Files | Refs

fzf-initialize.bash (2094B)


      1 # ble/contrib/integration/fzf-initialize.bash (C) 2020-2023, akinomyoga
      2 
      3 # Usage: Please write the following lines in blerc
      4 #
      5 # ```bash
      6 # _ble_contrib_fzf_base=/path/to/fzf-base-directory
      7 # ble-import -d integration/fzf-initialize
      8 # ```
      9 
     10 function ble/contrib/integration:fzf-completion/initialize {
     11   if [[ -d $_ble_contrib_fzf_base ]]; then
     12     if [[ -d $_ble_contrib_fzf_base/bin && :$PATH: != *:"$_ble_contrib_fzf_base/bin":* ]]; then
     13       export PATH="${PATH:+${PATH}:}$_ble_contrib_fzf_base/bin"
     14     fi
     15     if ! type fzf &>/dev/null; then
     16       echo 'ble/contrib/integration:fzf-initialize: "fzf" not found.' >&2
     17       return 1
     18     fi
     19   else
     20     local ret
     21     if ! ble/util/assign ret 'type -p fzf 2>/dev/null'; then
     22       echo 'ble/contrib/integration:fzf: "fzf" not found.' >&2
     23       return 1
     24     fi
     25     ble/util/readlink "$ret"
     26     ret=${ret%/*}      # fzf, fzf-linux_amd64, etc.
     27     ret=${ret%/bin}    # repo/bin/
     28     ret=${ret%/target} # repo/target (compile directory)
     29     if [[ -s $ret/shell/key-bindings.bash ]]; then
     30       _ble_contrib_fzf_base=$ret
     31     elif [[ -d $ret/share/fzf/shell ]]; then
     32       _ble_contrib_fzf_base=$ret/share/fzf
     33     elif [[ -s $ret/share/fzf/key-bindings.bash ]]; then
     34       # NixOS package (https://github.com/akinomyoga/blesh-contrib/pull/5#issuecomment-1019394821)
     35       _ble_contrib_fzf_base=$ret/share/fzf
     36     elif [[ -s $ret/share/doc/fzf/examples/key-bindings.bash ]]; then
     37       # Ubuntu fzf package (https://github.com/akinomyoga/blesh-contrib/pull/5#issuecomment-1019394821)
     38       _ble_contrib_fzf_base=$ret/share/doc/fzf/examples
     39     elif [[ -d /usr/share/fzf/shell ]]; then
     40       _ble_contrib_fzf_base=/usr/share/fzf
     41     elif [[ -d /usr/share/doc/fzf/examples/key-bindings.bash ]]; then
     42       # Ubuntu fzf package (https://github.com/akinomyoga/blesh-contrib/pull/5#issuecomment-1019394821)
     43       _ble_contrib_fzf_base=/usr/share/doc/fzf/examples
     44     else
     45       echo 'ble/contrib/integration:fzf: failed to find "fzf" base directory' >&2
     46       return 1
     47     fi
     48   fi
     49   return 0
     50 }
     51 
     52 ble/contrib/integration:fzf-completion/initialize || return 1