Subject: [bug#72482] [PATCH 3/3] gnu: Add shfmt.

From: Brian Kubisiak <[email-masked]>
Date: Mon, 5 Aug 2024 16:05:37 -0700

* gnu/packages/golang.scm (shfmt): New variable.

Change-Id: I7c8bcb0f0a1d0c45d5f8f2274724188a435f0cd7
---
 gnu/packages/golang.scm | 48 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/gnu/packages/golang.scm b/gnu/packages/golang.scm
index 63308d1af7..cf8e482bee 100644
--- a/gnu/packages/golang.scm
+++ b/gnu/packages/golang.scm
@@ -8120,6 +8120,54 @@ (define-public go-mvdan-cc-gofumpt
     (native-inputs '())
     (inputs '())))

+(define-public shfmt
+  (package
+    (name "shfmt")
+    (version "3.8.0")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/mvdan/sh")
+             (commit (string-append "v" version))))
+       (file-name (git-file-name name version))
+       (sha256
+        (base32 "13anc64m088plwazrx5c68m3nbnig7wxa92zqk83w83q16dx42fq"))
+       (modules '((guix build utils)))
+       (snippet #~(let ((fixed-version (string-append #$version " (GNU Guix)")))
+                    ;; shfmt uses modules to look up the version at runtime;
+                    ;; since our build system does not yet support modules,
+                    ;; inject the version string here instead
+                    (substitute* "cmd/shfmt/main.go"
+                      (("version = \"\\(devel\\)\"")
+                       (format #f "version = \"~a\"" fixed-version)))
+                    (substitute* "cmd/shfmt/testdata/script/flags.txtar"
+                      (("devel\\|v3")
+                       #$version))))))
+    (build-system go-build-system)
+    (arguments
+     (list
+      #:import-path "mvdan.cc/sh/v3/cmd/shfmt"
+      #:unpack-path "mvdan.cc/sh/v3"))
+    (inputs (list go-mvdan-cc-editorconfig
+                  go-golang-org-x-term
+                  go-golang-org-x-sys
+                  go-golang-org-x-sync
+                  go-github-com-rogpeppe-go-internal
+                  go-github-com-pkg-diff
+                  go-github-com-google-renameio-v2
+                  go-github-com-google-go-cmp-cmp
+                  go-github-com-frankban-quicktest
+                  go-github-com-creack-pty))
+    (home-page "https://github.com/mvdan/sh")
+    (synopsis "Shell formatter with bash support")
+    (description
+     "This package provides a shell formatter.  Supports
+@url{https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html,POSIX
+Shell}, @url{https://www.gnu.org/software/bash/,Bash}, and
+@url{http://www.mirbsd.org/mksh.htm,mksh}.")
+    (license license:bsd-3)))
+
 (define-public unparam
   (package
     (name "unparam")
--
2.45.2