unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: david larsson <david.larsson@selfhosted.xyz>
To: 51791@debbugs.gnu.org
Cc: Guix-patches <guix-patches-bounces+david.larsson=selfhosted.xyz@gnu.org>
Subject: [bug#51791] [PATCH 2/2 v2]: Update guile-bash
Date: Fri, 26 Nov 2021 20:16:12 +0100	[thread overview]
Message-ID: <650e73fe887c2524947b7c06d9dc9994@selfhosted.xyz> (raw)
In-Reply-To: <8d6b871864d52beebcdbe83cae97769c@selfhosted.xyz>

[-- Attachment #1: Type: text/plain, Size: 103 bytes --]

Forgot to update gnu/local.mk with the patch file for guile-bash so 
fixing that with this new patch.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-gnu-guile-bash-Add-patch-that-fixes-reading-args.patch --]
[-- Type: text/x-diff; name=0002-gnu-guile-bash-Add-patch-that-fixes-reading-args.patch, Size: 4101 bytes --]

From b5e120040b47e590aa276a2802aac53139a72196 Mon Sep 17 00:00:00 2001
From: David Larsson <david.larsson@selfhosted.xyz>
Date: Fri, 12 Nov 2021 13:42:41 +0100
Subject: [PATCH 2/2] gnu: guile-bash: Add patch that fixes reading args.

This patch allows guile-bash defined bash-functions
to read newline- or null-separated arguments from stdin,
making it usable in bash pipelines. It also fixes a bug
with arguments containing whitespace not being properly
passed to the corresponding guile function.

* gnu/packages/guile-xyz (guile-bash)[patches]: add patch.
* gnu/packages/patches/guile-bash-args-from-stdin.patch: new file.
* gnu/local.mk: add patch file.
---
 gnu/local.mk                                  |  1 +
 gnu/packages/guile-xyz.scm                    |  1 +
 .../patches/guile-bash-args-from-stdin.patch  | 42 +++++++++++++++++++
 3 files changed, 44 insertions(+)
 create mode 100644 gnu/packages/patches/guile-bash-args-from-stdin.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 05258ac054..fdc562b710 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1242,6 +1242,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/guile-3.0-relocatable.patch		\
   %D%/packages/patches/guile-linux-syscalls.patch		\
   %D%/packages/patches/guile-3.0-linux-syscalls.patch		\
+  %D%/packages/patches/guile-bash-args-from-stdin.patch		\
   %D%/packages/patches/guile-fibers-destroy-peer-schedulers.patch \
   %D%/packages/patches/guile-gdbm-ffi-support-gdbm-1.14.patch	\
   %D%/packages/patches/guile-present-coding.patch		\
diff --git a/gnu/packages/guile-xyz.scm b/gnu/packages/guile-xyz.scm
index 1d35c41796..511d766a6f 100644
--- a/gnu/packages/guile-xyz.scm
+++ b/gnu/packages/guile-xyz.scm
@@ -419,6 +419,7 @@ dictionary and suggesting spelling corrections.")
                 (uri (git-reference
                       (commit commit)
                       (url home-page)))
+                (patches (search-patches "guile-bash-args-from-stdin.patch"))
                 (sha256
                  (base32
                   "097vny990wp2qpjij6a5a5gwc6fxzg5wk56inhy18iki5v6pif1p"))
diff --git a/gnu/packages/patches/guile-bash-args-from-stdin.patch b/gnu/packages/patches/guile-bash-args-from-stdin.patch
new file mode 100644
index 0000000000..ad42616c70
--- /dev/null
+++ b/gnu/packages/patches/guile-bash-args-from-stdin.patch
@@ -0,0 +1,42 @@
+From a124921666a16cb4e93f59a653f98b99c78eb2ca Mon Sep 17 00:00:00 2001
+From: David Larsson <david.larsson@selfhosted.xyz>
+Date: Thu, 11 Nov 2021 14:07:04 +0100
+Subject: [PATCH] Enable reading arguments from bash via stdin
+
+* lisp/gnu/bash.scm(define-bash-function): read from stdin
+to SCM_ARGS array when it is open, and separate args by null
+instead of newline if -z option is passed as $1.
+---
+ lisp/gnu/bash.scm | 16 ++++++++++++----
+ 1 file changed, 12 insertions(+), 4 deletions(-)
+
+diff --git a/lisp/gnu/bash.scm b/lisp/gnu/bash.scm
+index 199ebc0..e9dcea5 100644
+--- a/lisp/gnu/bash.scm
++++ b/lisp/gnu/bash.scm
+@@ -326,10 +326,18 @@
+       (hashq-set! *funcs* symbol thunk)
+       (unsafe-format/eval
+        "function ~a {
+-            SCM_ARGS=($@)    ;
+-            local retval=$~a ;
+-            unset SCM_ARGS   ;
+-            return $retval   ;
++            local -a Input SCM_ARGS                                          ;
++            [[ ! -t 0 ]] && mapfile -d '' Input                              ;
++            if [[ -n \"${Input[@]}\" ]]; then
++                if [[ \"$1\" == -z ]]; then
++                    local -a SCM_ARGS=\"(${Input[*]@Q})\"                    ;
++                else
++                    mapfile -t SCM_ARGS < <(printf '%s' \"${Input[@]}\"); fi ;
++            else
++                SCM_ARGS=(\"$@\"); fi                                        ;
++            local retval=$~a                                                 ;
++            unset SCM_ARGS                                                   ;
++            return $retval                                                   ;
+        }"
+        symbol special-varname))))
+ 
+-- 
+2.31.0
+
-- 
2.31.0


  reply	other threads:[~2021-11-26 19:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-12 13:56 [bug#51791] [PATCH 0/2]: Update guile-bash david larsson
2021-11-12 14:00 ` [bug#51791] [PATCH 1/2]: " david larsson
2021-11-12 14:01 ` david larsson
2021-11-12 15:50 ` [bug#51791] [PATCH 2/2]: " david larsson
2021-11-26 19:16   ` david larsson [this message]
2021-12-01  7:20 ` [bug#51791] [PATCH 0/2]: " Ricardo Wurmus
2021-12-01 10:28 ` david larsson
2021-12-15 11:54 ` david larsson
2021-12-15 11:55 ` bug#51791: done david larsson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=650e73fe887c2524947b7c06d9dc9994@selfhosted.xyz \
    --to=david.larsson@selfhosted.xyz \
    --cc=51791@debbugs.gnu.org \
    --cc=guix-patches-bounces+david.larsson=selfhosted.xyz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).