Subject: [bug#66171] [PATCH v2] gnu: git: Install shell completions.

From: Liliana Marie Prikler <[email-masked]>
Date: Sat, 23 Sep 2023 21:43:07 +0200

* gnu/packages/version-control.scm (git)[outputs]: Add “completion”.
[#:phases]: Add ‘install-completion’.
(git-minimal)[#:phases]: Adjust accordingly.
---
Am Montag, dem 25.09.2023 um 13:12 +0200 schrieb Simon Tournier:
> Naive question: this also adds “completion” to git-minimal, no?  I mean,
> does the phase need to be deleted in git-minimal?
Indeed it does; updated the patch accordingly.

Cheers

 gnu/packages/version-control.scm | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/gnu/packages/version-control.scm b/gnu/packages/version-control.scm
index 9716a6f27a..35d17d434e 100644
--- a/gnu/packages/version-control.scm
+++ b/gnu/packages/version-control.scm
@@ -303,6 +303,7 @@ (define-public git
                "credential-netrc"       ; git-credential-netrc
                "credential-libsecret"   ; git-credential-libsecret
                "subtree"                ; git-subtree
+               "completion"             ; git-completion and git-prompt
                "gui"))                  ; gitk, git gui
     (arguments
      `(#:make-flags `("V=1"             ;more verbose compilation
@@ -482,6 +483,20 @@ (define-public git
                              (string-append subtree "/bin"))
                (install-file "contrib/subtree/git-subtree.1"
                              (string-append subtree "/share/man/man1")))))
+         (add-after 'install 'install-completion
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let ((completion (assoc-ref outputs "completion")))
+               (define (install-as file storename)
+                 (let ((storename (string-append completion storename)))
+                   (mkdir-p (dirname storename))
+                   (copy-file file storename)))
+               (with-directory-excursion "contrib/completion"
+                 (for-each (cut apply install-as <>)
+                           `(("git-prompt.sh" "/bin/git-prompt")
+                             ("git-completion.bash"
+                              "/share/bash-completion/completions/_git")
+                             ("git-completion.zsh"
+                              "/share/zsh/site-functions/_git")))))))
          (add-after 'install 'restore-sample-hooks-shebang
            (lambda* (#:key outputs #:allow-other-keys)
              (let* ((out (assoc-ref outputs "out"))
@@ -639,6 +654,7 @@ (define-public git-minimal
             (delete 'install-subtree)
             (delete 'install-credential-netrc)
             (delete 'install-credential-libsecret)
+            (delete 'install-completion)
             (add-after 'install 'remove-unusable-perl-commands
               (lambda* (#:key outputs #:allow-other-keys)
                 (let* ((out     (assoc-ref outputs "out"))

base-commit: e134686cead6db62ea8b941b2ed7c0bd660804da
-- 
2.41.0