sistema_progs

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

core-cmdspec.sh (10169B)


      1 # -*- mode: sh; mode: sh-bash -*-
      2 
      3 function ble/cmdspec/initialize { return 0; }
      4 
      5 function ble/complete/opts/initialize {
      6 
      7   ble/cmdspec/opts mandb-disable-man:no-options : false true
      8 
      9   ble/cmdspec/opts mandb-disable-man times
     10   ble/cmdspec/opts mandb-disable-man:mandb-help=%'help "$command"':stop-options-postarg pwd suspend
     11   local help_opt_help=
     12   if ((_ble_bash>=40400)); then
     13     # Note: 既に説明がある時に優先順位を下げる為にインデントは 8 文字にしている
     14     help_opt_help='          --help    Show help.'
     15     ble/cmdspec/opts +mandb-help=@"$help_opt_help" times pwd suspend
     16   fi
     17 
     18   local help_opt_basic=$help_opt_help'
     19         --    (indicate the end of options)'
     20   ble/cmdspec/opts mandb-disable-man:mandb-help=%'help "$command"':mandb-help=@"$help_opt_basic":stop-options-postarg \
     21     alias bind cd command compgen complete compopt declare dirs disown enable \
     22     exec export fc getopts hash help history jobs kill mapfile popd printf \
     23     pushd read readonly set shopt trap type ulimit umask unalias unset wait
     24   ble/cmdspec/opts mandb-disable-man:mandb-help=@"$help_opt_basic":stop-options-postarg . source fg bg builtin caller eval let
     25   ble/cmdspec/opts mandb-disable-man:mandb-help=@"$help_opt_basic":stop-options-postarg break continue exit logout return shift
     26 
     27   # [[
     28   local conditional_operators='
     29     -eq (NUM1 -eq NUM2)      Arithmetic comparison ==.
     30     -ne (NUM1 -ne NUM2)      Arithmetic comparison !=.
     31     -lt (NUM1 -lt NUM2)      Arithmetic comparison < .
     32     -le (NUM1 -le NUM2)      Arithmetic comparison <=.
     33     -gt (NUM1 -gt NUM2)      Arithmetic comparison > .
     34     -ge (NUM1 -ge NUM2)      Arithmetic comparison >=.
     35     -nt (FILE1 -nt FILE2)    True if file1 is newer than file2 (according to modification date).
     36     -ot (FILE1 -ot FILE2)    True if file1 is older than file2.
     37     -ef (FILE1 -ef FILE2)    True if file1 is a hard link to file2.'
     38   ble/cmdspec/opts disable-double-hyphen:mandb-help=%'help test':mandb-help=@"$conditional_operators" '[['
     39 
     40   # [, test
     41   local test_operators=$conditional_operators'
     42     -a (EXPR1 -a EXPR2)      True if both expr1 AND expr2 are true.
     43     -a (EXPR1 -o EXPR2)      True if either expr1 OR expr2 is true.'
     44   ble/cmdspec/opts disable-double-hyphen:mandb-help=%'help test':mandb-help=@"$test_operators":mandb-exclude='^--' 'test' '['
     45 
     46   # cd, dirs, popd, pushd (別に実装)
     47   ble/cmdspec/opts +plus-options:mandb-exclude='^[-+]N$' dirs popd pushd
     48 
     49 
     50   # complete, compgen
     51   local complete_flags='
     52     -A action       The action may be one of the following to generate a list
     53                     of possible completions---alias, arrayvar, binding,
     54                     builtin, command, directory, disabled, enabled, export,
     55                     file, function, group, helptopic, hostname, job, keyword,
     56                     running, service, setopt, shopt, signal, stopped, user,
     57                     variable.
     58     -o option       Set completion option OPTION for each NAME
     59     -a              Alias names.  May also be specified as `-A alias'\''.
     60     -b              Names of shell builtin commands.  May also be specified as
     61                     `-A builtin'\''.
     62     -c              Command names.  May also be specified as `-A command'\''.
     63     -d              Directory names.  May also be specified as `-A
     64                     directory'\''.
     65     -e              Names of exported shell variables.  May also be specified
     66                     as `-A export'\''.
     67     -f              File names.  May also be specified as `-A file'\''.
     68     -g              Group names.  May also be specified as `-A group'\''.
     69     -j              Job names, if job control is active.  May also be specified
     70                     as `-A job'\''.
     71     -k              Shell reserved words.  May also be specified as `-A
     72                     keyword'\''.
     73     -s              Service names.  May also be specified as `-A service'\''.
     74     -u              User names.  May also be specified as `-A user'\''.
     75     -v              Names of all shell variables.  May also be specified as `-A
     76                     variable'\''.
     77     -C command      command is executed in a subshell environment, and its
     78                     output is used as the possible completions.  Arguments are
     79                     passed as with the -F option.
     80     -F function     The shell function function is executed in the current
     81                     shell environment.  When the function is executed, the
     82                     first argument ($1) is the name of the command whose
     83                     arguments are being completed, the second argu- ment ($2)
     84                     is the word being completed, and the third argument ($3) is
     85                     the word preceding the word being completed on the current
     86                     command line.  When it finishes, the possible completions
     87                     are retrieved from the value of the COMPREPLY array
     88                     variable.
     89     -G globpat      The pathname expansion pattern globpat is expanded to
     90                     generate the possible completions.
     91     -P prefix       prefix is added at the beginning of each possible
     92                     completion after all other options have been applied.
     93     -S suffix       suffix is appended to each possible completion after all
     94                     other options have been applied.
     95     -W wordlist     The wordlist is split using the characters in the IFS
     96                     special variable as delimiters, and each resultant word is
     97                     expanded.  Shell quoting is honored within wordlist, in
     98                     order to provide a mechanism for the words to contain shell
     99                     metacharacters or characters in the value of IFS.  The
    100                     possible completions are the members of the resultant list
    101                     which match the word being completed.
    102     -X filterpat    filterpat is a pattern as used for pathname expansion.  It
    103                     is applied to the list of possible completions generated by
    104                     the preceding options and arguments, and each completion
    105                     matching filterpat is removed from the list.  A leading !
    106                     in filterpat negates the pattern; in this case, any
    107                     completion not matching filterpat is removed.'
    108   ble/cmdspec/opts +mandb-help-usage:mandb-help=@"$complete_flags" complete compgen
    109 
    110   # compopt
    111   ble/cmdspec/opts +plus-options=o compopt
    112 
    113   # declare, typeset, local
    114   ble/cmdspec/opts mandb-disable-man:mandb-help=%'help declare':mandb-help=@"$help_opt_basic":stop-options-postarg typeset local
    115   ble/cmdspec/opts +plus-options=aAilnrtux declare typeset local
    116 
    117   # echo
    118   ble/cmdspec/opts mandb-disable-man:mandb-help=%'help echo':stop-options-unless='^-[neE]+$' echo
    119 
    120   # fc
    121   ble/cmdspec/opts +mandb-help=@'
    122         -s          With the `fc -s [pat=rep ...] [command]'\'' format, COMMAND
    123                     is re-executed after the substitution OLD=NEW is performed.' fc
    124 
    125   # jobs
    126   ble/cmdspec/opts +mandb-help=@'
    127         -x          If -x is supplied, COMMAND is run after all job
    128                     specifications that appear in ARGS have been replaced with
    129                     the process ID of that job'\''s process group leader.' jobs
    130 
    131   # readarray -> mapfile
    132   ble/cmdspec/opts mandb-disable-man:mandb-help=%'help mapfile':mandb-help=@"$help_opt_basic":stop-options-postarg readarray
    133 
    134   # set
    135   ble/cmdspec/opts +plus-options=abefhkmnptuvxBCEHPTo set
    136 
    137   # wait
    138   ((_ble_bash>=40300)) &&
    139     ble/cmdspec/opts +mandb-help-usage:mandb-help=@'
    140         -n          waits for a single job from the list of IDs, or, if no IDs
    141                     are supplied, for the next job to complete and returns its
    142                     exit status.' wait
    143   ((_ble_bash>=50000)) &&
    144     ble/cmdspec/opts +mandb-help-usage:mandb-help=@'
    145         -f          If job control is enabled, waits for the specified ID to
    146                     terminate, instead of waiting for it to change status.' wait
    147   ((_ble_bash>=50100)) &&
    148     ble/cmdspec/opts +mandb-help-usage:mandb-help=@'
    149         -p          the process or job identifier of the job for which the exit
    150                     status is returned is assigned to the variable VAR named by
    151                     the option argument. The variable will be unset initially,
    152                     before any assignment. This is useful only when the -n
    153                     option is supplied.' wait
    154 
    155   ble/cmdspec/opts mandb-help rsync
    156 }
    157 ble/complete/opts/initialize
    158 
    159 
    160 function ble/cmdinfo/cmd:declare/chroma.wattr {
    161   local ret
    162   if ((wtype==_ble_attr_VAR)); then
    163     ble/syntax:bash/find-rhs "$wtype" "$wbeg" "$wlen" element-assignment &&
    164       ble/progcolor/highlight-filename.wattr "$ret" "$wend"
    165   else
    166     ble/progcolor/eval-word || return "$?"
    167     local wval=$ret
    168 
    169     if ble/string#match "$wval" '^([_a-zA-Z][_a-zA-Z0-9]*)(\[.+\])?$'; then
    170       # ToDo: properly support quoted case
    171       local varname=${BASH_REMATCH[1]}
    172       ble/syntax/highlight/vartype "$varname" global
    173       ble/progcolor/wattr#setattr "$wbeg" "$ret"
    174       ble/progcolor/wattr#setattr "$((wbeg+${#varname}))" d
    175     elif ble/string#match "$wval" '^[-+]' && ble/progcolor/is-option-context; then
    176       # ToDo: validate available options
    177       local ret; ble/color/face2g argument_option
    178       ble/progcolor/wattr#setg "$wbeg" "$ret"
    179     else
    180       local ret; ble/color/face2g argument_error
    181       ble/progcolor/wattr#setg "$wbeg" "$ret"
    182     fi
    183   fi
    184   return 0
    185 }
    186 
    187 function ble/cmdinfo/cmd:declare/chroma {
    188   local i "${_ble_syntax_progcolor_vars[@]/%/=}" # WA #D1570 checked
    189   for ((i=1;i<${#comp_words[@]};i++)); do
    190     local ref=${tree_words[i]}
    191     [[ $ref ]] || continue
    192     local progcolor_iword=$i
    193     ble/progcolor/load-word-data "$ref"
    194     ble/progcolor/@wattr ble/cmdinfo/cmd:declare/chroma.wattr
    195   done
    196 }
    197 function ble/cmdinfo/cmd:typeset/chroma  { ble/cmdinfo/cmd:declare/chroma "$@"; }
    198 function ble/cmdinfo/cmd:local/chroma    { ble/cmdinfo/cmd:declare/chroma "$@"; }
    199 function ble/cmdinfo/cmd:readonly/chroma { ble/cmdinfo/cmd:declare/chroma "$@"; }
    200 function ble/cmdinfo/cmd:export/chroma   { ble/cmdinfo/cmd:declare/chroma "$@"; }