sistema_progs

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

D1120.resolve1.sh (1672B)


      1 #!/bin/bash
      2 
      3 function ble/history:bash/resolve-multiline/.worker {
      4   local apos=\'
      5   local HISTTIMEFORMAT=__ble_ext__
      6   local -x HISTORY_SOURCE=$1
      7   builtin history $arg_count | ble/bin/awk -v apos="$apos" '
      8     BEGIN {
      9       n = 0;
     10       hindex = 0;
     11       FILE_HISTORY = ENVIRON["HISTORY_SOURCE"];
     12       print "builtin history -c" > FILE_HISTORY;
     13       multiline_count = 0;
     14       modification_count = 0;
     15     }
     16 
     17     function flush_line() {
     18       if (n < 1) return;
     19 
     20       if (entry ~ /^eval -- \$'$apos'([^'$apos'\\]|\\.)*'$apos'$/) {
     21         multiline_count++;
     22         modification_count++;
     23         print "builtin history -s -- " substr(entry, 9) > FILE_HISTORY;
     24       } else {
     25         if (n > 1) multiline_count++;
     26         gsub(/'$apos'/, "'$apos'\\'$apos$apos'", entry);
     27         entry = apos entry apos;
     28         print "builtin history -s -- " entry > FILE_HISTORY;
     29       }
     30 
     31       n = 0;
     32       entry = "";
     33     }
     34 
     35     {
     36       if (sub(/^ *[0-9]+\*? +(__ble_ext__|\?\?)/, "", $0))
     37         flush_line();
     38       entry = ++n == 1 ? $0 : entry "\n" $0;
     39     }
     40 
     41     END {
     42       flush_line();
     43       print "builtin history -a /dev/null" > FILE_HISTORY
     44       print "multiline_count=" multiline_count;
     45       print "modification_count=" modification_count;
     46     }
     47   '
     48 }
     49 function ble/history:bash/resolve-multiline {
     50   local foutput=history_resolve_multiline.out
     51   local multiline_count=0 modification_count=0
     52   eval -- $(ble/history:bash/resolve-multiline/.worker "$foutput" 2>/dev/null)
     53   echo "modification_count=$modification_count"
     54   if ((modification_count)); then
     55      local HISTCONTROL= HISTSIZE= HISTIGNORE=
     56      time source "$foutput"
     57   fi
     58 }
     59 ble/history:bash/resolve-multiline