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

Message ID 71d35b161b07d6d4193a173d4e51dbb61338c752.1744949439.git.wongandj@icloud.com
State New
Headers
Series [bug#77884] gnu: trash-cli: Install shell completions. |

Commit Message

Andrew Wong April 18, 2025, 4:10 a.m. UTC
  * 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(-)


base-commit: f7c41ab31f5023023385500f6eb9083d23dd1ccb
  

Patch

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