sistema_progs

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

github288-filter-sabbrev-completion.bash (2716B)


      1 # blesh/contrib/config/github288-filter-sabbrev-completion.bash (C) 2023, Koichi Murase <myoga.murase@gmail.com>
      2 
      3 # The option "bleopt complete_source_sabbrev_command_ignore" specifies a
      4 # colon-separated list of glob patterns of command names for which the sabbrev
      5 # completion should be suppressed.
      6 bleopt/declare -v complete_source_sabbrev_command_ignore ''
      7 
      8 _ble_contrib_config_github288_command_ignore_patterns=()
      9 function bleopt/check:complete_source_sabbrev_command_ignore {
     10   if [[ $value ]]; then
     11     ble/string#split _ble_contrib_config_github288_command_ignore_patterns : "$value"
     12   else
     13     _ble_contrib_config_github288_command_ignore_patterns=()
     14   fi
     15 }
     16 bleopt -I complete_source_sabbrev_command_ignore
     17 
     18 # This is an "advice" function for the exiting function
     19 # "ble/complete/source:sabbrev", i.e., the function to modify the behavior of
     20 # the original function.  We insert some codes before starting the original
     21 # processing.
     22 function ble/contrib/config:github288/filter-sabbrev-completion.advice {
     23   # If we are generating sabbrevs as a part of argument completions and if
     24   # there are any ignore patterns for the command names in
     25   # "complete_source_sabbrev_command_ignore", we make the sabbrev completions
     26   # inactive for the commands matching an ignore pattern.
     27   if [[ ${ADVICE_FUNCNAME[1]} == ble/complete/source:argument ]]; then
     28     if ((${#_ble_contrib_config_github288_command_ignore_patterns[@]})); then
     29       # Extract the command name and arguments on the current caret position.
     30       local comp_words comp_line comp_point comp_cword
     31       ble/syntax:bash/extract-command "$_ble_edit_ind" || return 1
     32 
     33       # If the command word is simple enough, we evaluate the command word to
     34       # resolve quoting and parameter expansions.
     35       local cmd=${comp_words[0]} ret
     36       ble/syntax:bash/simple-word/is-simple "$cmd" &&
     37         ble/syntax:bash/simple-word/eval "$cmd" &&
     38         cmd=$ret
     39 
     40       # If the command name matches any pattern of the ignored list, we return
     41       # the function without calling the original function.
     42       ble/complete/string#match-patterns "$cmd" "${_ble_contrib_config_github288_command_ignore_patterns[@]}" &&
     43         return 1
     44     fi
     45   fi
     46 
     47   # We call the original "ble/complete/source:sabbrev" here.  The original
     48   # function, i.e., the advice target, can be called by ble/function#advice/do.
     49   ble/function#advice/do
     50 }
     51 
     52 function ble/contrib/config:github288/initialize.hook {
     53   # We hook the above "advice" function to "ble/complete/source:sabbrev".
     54   ble/function#advice around ble/complete/source:sabbrev ble/contrib/config:github288/filter-sabbrev-completion.advice
     55 }
     56 blehook/eval-after-load complete ble/contrib/config:github288/initialize.hook