sistema_progs

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

D1120.resolve3.sh (2450B)


      1 #!/bin/bash
      2 
      3 function ble/history:bash/resolve-multiline/.worker {
      4   local apos=\'
      5   local HISTTIMEFORMAT=__ble_ext__
      6   builtin history | ble/bin/awk -v apos="$apos" '
      7     BEGIN {
      8       n = 0;
      9 
     10       TMPBASE = ENVIRON["TMPBASE"];
     11       filename_source = TMPBASE ".sh";
     12 
     13       q = apos;
     14       Q = apos "\\" apos apos;
     15 
     16       print "builtin history -c" > filename_source;
     17       multiline_count = 0;
     18       modification_count = 0;
     19 
     20       read_section_count = 0;
     21     }
     22 
     23     function write_scalar(line) {
     24       scalar_array[scalar_count++] = line;
     25     }
     26     function write_complex(value) {
     27       write_flush();
     28       print "builtin history -s -- " value > filename_source;
     29     }
     30     function write_flush(_, i, text, filename) {
     31       if (scalar_count == 0) return;
     32       if (scalar_count >= 2) {
     33         filename_section = TMPBASE "." read_section_count++ ".part";
     34         for (i = 0; i < scalar_count; i++)
     35           print scalar_array[i] > filename_section;
     36         print "builtin history -r " filename_section > filename_source;
     37       } else {
     38         for (i = 0; i < scalar_count; i++) {
     39           text = scalar_array[i];
     40           gsub(/'$apos'/, Q, text);
     41           print "builtin history -s -- " q text q > filename_source;
     42         }
     43       }
     44       scalar_count = 0;
     45     }
     46 
     47     function flush_line() {
     48       if (n < 1) return;
     49 
     50       if (entry ~ /^eval -- \$'$apos'([^'$apos'\\]|\\.)*'$apos'$/) {
     51         multiline_count++;
     52         modification_count++;
     53         write_complex(substr(entry, 9));
     54       } else if (n > 1) {
     55         multiline_count++;
     56         gsub(/'$apos'/, Q, entry);
     57         write_complex(q entry q);
     58       } else {
     59         write_scalar(entry);
     60       }
     61 
     62       n = 0;
     63       entry = "";
     64     }
     65 
     66     {
     67       if (sub(/^ *[0-9]+\*? +(__ble_ext__|\?\?)/, "", $0))
     68         flush_line();
     69       entry = ++n == 1 ? $0 : entry "\n" $0;
     70     }
     71 
     72     END {
     73       flush_line();
     74       write_flush();
     75       print "builtin history -a /dev/null" > filename_source
     76       print "multiline_count=" multiline_count;
     77       print "modification_count=" modification_count;
     78     }
     79   '
     80 }
     81 function ble/history:bash/resolve-multiline {
     82   local -x TMPBASE=$_ble_base_run/$$.history.multiline-resolve
     83   local multiline_count=0 modification_count=0
     84   eval -- $(ble/history:bash/resolve-multiline/.worker 2>/dev/null)
     85   if ((modification_count)); then
     86      local HISTCONTROL= HISTSIZE= HISTIGNORE=
     87      time source "$TMPBASE.sh"
     88   fi
     89 }
     90 ble/history:bash/resolve-multiline