sistema_progs

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

D1259.readbind.sh (1904B)


      1 # -*- mode: sh; mode: sh-bash -*-
      2 
      3 q=\'
      4 {
      5   for map in vi-insert vi-command emacs; do
      6     echo __CLEAR__
      7     echo KEYMAP="$map"
      8     echo __BIND0__
      9     "$BASH" --norc -i -c "bind -m $map -p" | sed '/^#/d;s/"\\M-/"\\e/'
     10     echo __BINDX__
     11     builtin bind -m "$map" -X
     12     echo __BINDS__
     13     builtin bind -m "$map" -s
     14     echo __BINDP__
     15     builtin bind -m "$map" -p
     16     echo __PRINT__
     17   done
     18 } | LC_ALL= LC_CTYPE=C awk -v q="$q" '
     19   function keymap_register(key, val, type) {
     20     if (!haskey[key]) {
     21       keys[nkey++] = key;
     22       haskey[key] = 1;
     23     }
     24     keymap[key] = val;
     25     keymap_type[key] = type;
     26   }
     27   function keymap_clear(_, i, key) {
     28     for(i = 0; i < nkey; i++) {
     29       key = keys[i];
     30       delete keymap[key];
     31       delete keymap_type[key];
     32       delete keymap0[key];
     33       haskey[key] = 0;
     34     }
     35     nkey = 0;
     36   }
     37   function keymap_print(_, i, key, type, value, text, line) {
     38     for (i = 0; i < nkey; i++) {
     39       key = keys[i];
     40       type = keymap_type[key];
     41       value = keymap[key];
     42       if (type == "" && value == keymap0[key]) continue;
     43 
     44       text = key ": " value;
     45       gsub(/'$q'/, q "\\" q q, text);
     46 
     47       line = "bind";
     48       if (KEYMAP != "") line = line " -m " KEYMAP;
     49       if (type == "x") line = line " -x";
     50       line = line " " q text q;
     51       print line;
     52     }
     53   }
     54 
     55   /^__BIND0__$/ { mode = 0; next; }
     56   /^__BINDX__$/ { mode = 1; next; }
     57   /^__BINDS__$/ { mode = 2; next; }
     58   /^__BINDP__$/ { mode = 3; next; }
     59   /^__CLEAR__$/ { keymap_clear(); next; }
     60   /^__PRINT__$/ { keymap_print(); next; }
     61   sub(/^KEYMAP=/, "") { KEYMAP = $0; }
     62 
     63   /ble-decode\/.hook / { next; }
     64 
     65   match($0, /^"(\\.|[^"])+": /) {
     66     key = substr($0, 1, RLENGTH - 2);
     67     val = substr($0, 1 + RLENGTH);
     68     gsub(/\\M-/, "\\e", key);
     69     if (mode) {
     70       type = mode == 1 ? "x" : mode == 2 ? "s" : "";
     71       keymap_register(key, val, type);
     72     } else {
     73       keymap0[key] = val;
     74     }
     75   }
     76 '