bournish: 'ls' lists directory contents.

Suggested by Ricardo Wurmus.

* guix/build/bournish.scm (ls-command-implementation): When FILE is a
directory, list its contents rather than FILE itself.
This commit is contained in:
Ludovic Courtès 2017-05-13 15:24:38 +02:00
parent 0e40b75506
commit c7d1b061f5
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
1 changed files with 25 additions and 11 deletions

View File

@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2016 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2016, 2017 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2016 Efraim Flashner <efraim@flashner.co.il> ;;; Copyright © 2016 Efraim Flashner <efraim@flashner.co.il>
;;; Copyright © 2017 Ricardo Wurmus <rekado@elephly.net> ;;; Copyright © 2017 Ricardo Wurmus <rekado@elephly.net>
;;; ;;;
@ -81,16 +81,30 @@ characters."
(() (()
(display-tabulated (scandir "."))) (display-tabulated (scandir ".")))
(files (files
(let ((files (filter (lambda (file) (let ((files (append-map (lambda (file)
(catch 'system-error (catch 'system-error
(lambda () (lambda ()
(lstat file)) (match (stat:type (lstat file))
(lambda args ('directory
(let ((errno (system-error-errno args))) ;; Like GNU ls, list the contents of
(format (current-error-port) "~a: ~a~%" ;; FILE rather than FILE itself.
file (strerror errno)) (match (scandir file
#f)))) (match-lambda
files))) ((or "." "..") #f)
(_ #t)))
(#f
(list file))
((files ...)
(map (cut string-append file "/" <>)
files))))
(_
(list file))))
(lambda args
(let ((errno (system-error-errno args)))
(format (current-error-port) "~a: ~a~%"
file (strerror errno))
'()))))
files)))
(display-tabulated files))))) (display-tabulated files)))))
(define (ls-command . files) (define (ls-command . files)