unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Robert Vollmert <rob@vllmrt.net>
To: guix-devel@gnu.org
Subject: small hack to prettify output of list-installed
Date: Fri, 19 Jul 2019 09:46:15 +0200	[thread overview]
Message-ID: <FCA3A985-1A10-48BE-9DE4-88E409824E84@vllmrt.net> (raw)

Hi,

here’s a small patch that calls “column -t” on the output of
`guix package --list-installed`. Probably not suitable for
inclusion since I assume the guix scripts shouldn’t depend
on `util-linux`, but I find it quite nice to have, so maybe
it’s useful to someone else.

Robert

From 1c6bf7e150445126448f1d5be4822889961f451f Mon Sep 17 00:00:00 2001
From: Robert Vollmert <rob@vllmrt.net>
Date: Fri, 19 Jul 2019 09:40:53 +0200
Subject: [PATCH] columnize list-installed and list-available

---
 guix/scripts/package.scm | 49 ++++++++++++++++++++++++----------------
 1 file changed, 30 insertions(+), 19 deletions(-)

diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm
index a43c96516f..ee7d16062b 100644
--- a/guix/scripts/package.scm
+++ b/guix/scripts/package.scm
@@ -43,6 +43,7 @@
                 #:select (directory-exists? mkdir-p))
   #:use-module (ice-9 format)
   #:use-module (ice-9 match)
+  #:use-module (ice-9 popen)
   #:use-module (ice-9 regex)
   #:use-module (ice-9 vlist)
   #:use-module (srfi srfi-1)
@@ -55,6 +56,7 @@
   #:autoload   (gnu packages base) (canonical-package)
   #:autoload   (gnu packages guile) (guile-2.2)
   #:autoload   (gnu packages bootstrap) (%bootstrap-guile)
+  #:autoload   (gnu packages linux) (util-linux)
   #:export (build-and-use-profile
             delete-generations
             delete-matching-generations
@@ -654,6 +656,11 @@ doesn't need it."
 ;;; Queries and actions.
 ;;;
 
+(define (columnize thunk)
+  (let ((port (open-output-pipe "column -t")))
+    (with-output-to-port port thunk)
+    (close-pipe port)))
+
 (define (process-query opts)
   "Process any query specified by OPTS.  Return #t when a query was actually
 processed, #f otherwise."
@@ -703,15 +710,17 @@ processed, #f otherwise."
               (manifest  (profile-manifest profile))
               (installed (manifest-entries manifest)))
          (leave-on-EPIPE
-          (for-each (match-lambda
-                      (($ <manifest-entry> name version output path _)
-                       (when (or (not regexp)
-                                 (regexp-exec regexp name))
-                         (format #t "~a\t~a\t~a\t~a~%"
-                                 name (or version "?") output path))))
-
-                    ;; Show most recently installed packages last.
-                    (reverse installed)))
+          (columnize
+           (lambda ()
+             (for-each (match-lambda
+                         (($ <manifest-entry> name version output path _)
+                          (when (or (not regexp)
+                                    (regexp-exec regexp name))
+                            (format #t "~a\t~a\t~a\t~a~%"
+                                    name (or version "?") output path))))
+
+                       ;; Show most recently installed packages last.
+                       (reverse installed)))))
          #t))
 
       (('list-available regexp)
@@ -734,16 +743,18 @@ processed, #f otherwise."
                                 result))
                           '())))
          (leave-on-EPIPE
-          (for-each (match-lambda
-                      ((name version outputs location)
-                       (format #t "~a\t~a\t~a\t~a~%"
-                               name version
-                               (string-join outputs ",")
-                               (location->string location))))
-                    (sort available
-                          (match-lambda*
-                            (((name1 . _) (name2 . _))
-                             (string<? name1 name2))))))
+          (columnize
+           (lambda ()
+             (for-each (match-lambda
+                         ((name version outputs location)
+                          (format #t "~a\t~a\t~a\t~a~%"
+                                  name version
+                                  (string-join outputs ",")
+                                  (location->string location))))
+                       (sort available
+                             (match-lambda*
+                               (((name1 . _) (name2 . _))
+                                (string<? name1 name2))))))))
          #t))
 
       (('search _)
-- 
2.21.0

             reply	other threads:[~2019-07-19  7:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-19  7:46 Robert Vollmert [this message]
2019-07-19  8:32 ` small hack to prettify output of list-installed Danny Milosavljevic
2019-07-19 16:21   ` Robert Vollmert
2019-07-22 14:25     ` Danny Milosavljevic

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=FCA3A985-1A10-48BE-9DE4-88E409824E84@vllmrt.net \
    --to=rob@vllmrt.net \
    --cc=guix-devel@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).