]> git.nbdom.net Git - nb.git/commitdiff
Use open instead of ticks
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 14 Dec 2022 13:20:45 +0000 (14:20 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 14 Dec 2022 13:20:45 +0000 (14:20 +0100)
bin/shell-replace
etc/vim/source/vars.vim

index 0a993dc7ae5141b0d67489579cdf9169ad84a0fd..e944f262b7d6515dc3274d88fc6ce553e1bee7aa 100755 (executable)
@@ -190,19 +190,26 @@ sub wanted {
        close $hfile;
 }
 
+#use String::ShellQuote;
 sub cmd {
        my $cmd = join(' ',@_);
+       # NB 14.12.22 #$cmd =~ s/\$'\\t'/"\t"/g;
+       #$cmd =~ s/(')/\\$1/g;
+# NB 14.12.22 #die $cmd;
+       # NB 14.12.22 my @cmd = `$cmd`;
+       # NB 14.12.22 die "$!" if $?;
+       # NB 14.12.22 return wantarray ? @cmd : join('',@cmd);
        my $hcmd;
-#die $_;
-       my @cmd = `$cmd`;
-       die "$!" if $?;
+       my $pid;
+       die $! unless defined ($pid = open($hcmd,"-|"));
+       if ($pid == 0) {
+               exec "$cmd";
+       }
+       my @cmd = <$hcmd>;
+       close $hcmd;
+       #waitpid $pid,0;
+       die "ERROR $cmd: $!" if $? != 0;
        return wantarray ? @cmd : join('',@cmd);
-       # NB 13.12.22 $cmd =~ s/"/\\"/g;
-       # NB 13.12.22 open reurn pid if command failed, so die never called: open($hcmd,qq/bash -lc "$cmd" |/) or die $!;
-       # NB 13.12.22 open($hcmd,"$cmd |") or die $!;
-       # NB 13.12.22 my @cmd = <$hcmd>;
-       # NB 13.12.22 close $hcmd;
-       # NB 13.12.22 return wantarray ? @cmd : join('',@cmd);
 }
 
 sub shell_replace {
@@ -364,7 +371,7 @@ $NAME --find path/
 Find files which contains start and tags >SHELL_REPLACE .. <SHELL_REPLACE.
 Execute the command aflter the start tag and replace the lines until the end tag.
 Example of file content:
-#>SHELL_REPLACE dbq.php nb meta ls key,val cat=mime.comment format=vim_hash preff=$'\t' name=mimeComment
+#>SHELL_REPLACE Shell command
 .....
 #<SHELL_REPLACE
 
index f66598c0564b41202c87e2398b07a97f6c419971..5e6b39992ec5800c3cdc699e059b04288e7b4958 100644 (file)
@@ -9,7 +9,7 @@ let mimeExt = {
 let mimeAliases = {
        \ 'sh' : 'bash'
 \}
-">SHELL_REPLACE dbq.php nb meta ls key,val cat=file.check format=vim_hash preff=$'\t' name=mimeCheck
+">SHELL_REPLACE dbq db=nb t=meta action=table.rows rows.fields=key,val cat=file.check format=vim_hash name=mimeCheck preff="$(printf "\t")"
 let mimeCheck = {
        \ 'awk'    : 'awk < /dev/null --lint=no-ext --file'
        \,'bash'   : 'bash -c'
@@ -30,7 +30,7 @@ let mimeCheck = {
 \}
 "<SHELL_REPLACE
 
-">SHELL_REPLACE dbq.php nb meta ls key,val cat=mime.comment format=vim_hash preff=$'\t' name=mimeComment
+">SHELL_REPLACE dbq.php nb meta ls key,val cat=mime.comment format=vim_hash preff="$(printf "\t")" name=mimeComment
 let mimeComment = {
        \ 'bindzone'  : ';'
        \,'c'         : '//'