[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
small hack to prettify output of list-installed
From: |
Robert Vollmert |
Subject: |
small hack to prettify output of list-installed |
Date: |
Fri, 19 Jul 2019 09:46:15 +0200 |
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 <address@hidden>
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
- small hack to prettify output of list-installed,
Robert Vollmert <=