Subject: [bug#77884] [PATCH] gnu: trash-cli: Install shell completions.

From: Andrew Wong <[email-masked]>
Date: Fri, 18 Apr 2025 00:10:39 -0400

* gnu/packages/shellutils.scm (trash-cli)[arguments]<#:phases>Install shell completions.

Change-Id: I0b165155d1da8069837bd9b93990dfaf0ff7de52
---
 gnu/packages/shellutils.scm | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/shellutils.scm b/gnu/packages/shellutils.scm
index ea6dcafbc9..aae50d8d4c 100644
--- a/gnu/packages/shellutils.scm
+++ b/gnu/packages/shellutils.scm
@@ -672,7 +672,31 @@ (define-public trash-cli
                    (replace 'check
                      (lambda* (#:key tests? #:allow-other-keys)
                        (when tests?
-                         (invoke "pytest")))))))
+                         (invoke "pytest"))))
+                   (add-after 'wrap 'install-completions
+                     (lambda _
+                       (for-each
+                        (lambda (binary)
+                          (for-each
+                           (lambda (shell-completion-data)
+                             (mkdir-p
+                              (string-append
+                               #$output (dirname (cdr shell-completion-data))))
+                             (with-output-to-file
+                                 (format
+                                  #f (string-append
+                                      #$output (cdr shell-completion-data))
+                                  (basename binary))
+                               (lambda _
+                                 (invoke binary "--print-completion"
+                                         (car shell-completion-data)))))
+                           '(("bash" . "/share/bash-completion/completions/~a")
+                             ("zsh" . "/share/zsh/site-functions/_~a")
+                             ("tcsh" . "/etc/profile.d/~a.completion.csh"))))
+                        (find-files
+                         (string-append #$output "/bin/")
+                         (lambda (file stat)
+                           (not (string-suffix? "-real" file))))))))))
     (native-inputs (list python-flexmock
                          python-mock
                          python-parameterized

base-commit: f7c41ab31f5023023385500f6eb9083d23dd1ccb
-- 
2.49.0