Hi, I'm attaching the diff.
Some comments: 1. 'psd-list' is a potential bottleneck. It will cause problems when we have more packages. If it's possible to evaluate it lazily, I'll rewrite it. (I haven't checked yet.) 2. The above is valid for 'package?' too. Also, it's probably possible to rewrite it using 'match', but I haven't found a way to do so. 3. The command-line part just mimics 'list-available'. (Maybe there is a better way.) 4. I've noticed that 'fold-packages' returns duplicates. Should it be fixed? Should I filter the output instead? Examples: # ./pre-inst-env guile scheme@(guile-user)> ,use (guix ui) (gnu packages) (guix packages) scheme@(guile-user)> (for-each display (sort (map (lambda (x) (string-append (package-name x) " " (location->string (package-location x)) "\n")) (fold-packages cons '())) string<?)) [...] glibc gnu/packages/base.scm:497:3 glibc gnu/packages/base.scm:497:3 [...] guile gnu/packages/guile.scm:93:3 guile gnu/packages/guile.scm:93:3 # ./pre-inst-env guix-package -s "C library" [...] glibc 2.17 gnu/packages/base.scm:497:3 glibc 2.17 gnu/packages/base.scm:497:3 # ./pre-inst-env guix-package -s Guile [...] guile 2.0.7 gnu/packages/guile.scm:93:3 guile 2.0.7 gnu/packages/guile.scm:93:3 Nikita
--- guix-package-orig 2013-01-20 16:43:13.000000000 +0000 +++ guix-package 2013-01-20 20:47:38.000000000 +0000 @@ -230,6 +230,32 @@ (leave (_ "error: no previous profile; not rolling back~%"))) (else (switch-link))))) +(define (sd-search rx) + "Search in SYNOPSIS and DESCRIPTION using RX. Return a list of +matching packages." + (define psd-list + ;; Return a list of lists (each inner list contains PACKAGE-NAME, + ;; SYNOPSIS, and DESCRIPTION of every package). + (map (lambda (x) + (list x (package-synopsis x) (package-description x))) + (fold-packages cons '()))) + + (define (matcher str) + ;; Match RX against STR. Return the result or #f if nothing was + ;; found. + (false-if-exception (match:substring (regexp-exec rx str) 0))) + + (define (package? lst) + ;; Return PACKAGE wrapped in a list or '() if match failed. + (if (any (cut matcher <>) (list (cadr lst) (caddr lst))) + (list (car lst)) + '())) + + (sort (append-map package? psd-list) + (lambda (p1 p2) + (string<? (package-name p1) + (package-name p2))))) + ;;; ;;; Command-line options. @@ -261,6 +287,8 @@ --verbose produce verbose output")) (newline) (display (_ " + -s, --search=REGEXP search in synopsis and description using REGEXP")) + (display (_ " -I, --list-installed[=REGEXP] list installed packages matching REGEXP")) (display (_ " @@ -306,6 +334,10 @@ (option '("verbose") #f #f (lambda (opt name arg result) (alist-cons 'verbose? #t result))) + (option '(#\s "search") #t #f + (lambda (opt name arg result) + (cons `(query search ,(or arg "")) + result))) (option '(#\I "list-installed") #f #t (lambda (opt name arg result) (cons `(query list-installed ,(or arg "")) @@ -526,6 +558,7 @@ name (or version "?") output path)))) installed) #t)) + (('list-available regexp) (let* ((regexp (and regexp (make-regexp regexp))) (available (fold-packages @@ -548,6 +581,16 @@ (string<? (package-name p1) (package-name p2))))) #t)) + + (('search regexp) + (let ((regexp (and regexp (make-regexp regexp)))) + (for-each (lambda (p) + (format #t "~a\t~a\t~a~%" + (package-name p) + (package-version p) + (location->string (package-location p)))) + (sd-search regexp)) + #t)) (_ #f)))) (setlocale LC_ALL "")
pgpnuYaVVDcC5.pgp
Description: PGP signature