[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
01/02: bournish: 'ls' lists directory contents.
From: |
Ludovic Courtès |
Subject: |
01/02: bournish: 'ls' lists directory contents. |
Date: |
Sat, 13 May 2017 10:52:27 -0400 (EDT) |
civodul pushed a commit to branch master
in repository guix.
commit c7d1b061f5e3fb33085e8dc06431517da5f4abfb
Author: Ludovic Courtès <address@hidden>
Date: Sat May 13 15:24:38 2017 +0200
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.
---
guix/build/bournish.scm | 36 +++++++++++++++++++++++++-----------
1 file changed, 25 insertions(+), 11 deletions(-)
diff --git a/guix/build/bournish.scm b/guix/build/bournish.scm
index e948cd0..7aa1f8c 100644
--- a/guix/build/bournish.scm
+++ b/guix/build/bournish.scm
@@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2016 Ludovic Courtès <address@hidden>
+;;; Copyright © 2016, 2017 Ludovic Courtès <address@hidden>
;;; Copyright © 2016 Efraim Flashner <address@hidden>
;;; Copyright © 2017 Ricardo Wurmus <address@hidden>
;;;
@@ -81,16 +81,30 @@ characters."
(()
(display-tabulated (scandir ".")))
(files
- (let ((files (filter (lambda (file)
- (catch 'system-error
- (lambda ()
- (lstat file))
- (lambda args
- (let ((errno (system-error-errno args)))
- (format (current-error-port) "~a: ~a~%"
- file (strerror errno))
- #f))))
- files)))
+ (let ((files (append-map (lambda (file)
+ (catch 'system-error
+ (lambda ()
+ (match (stat:type (lstat file))
+ ('directory
+ ;; Like GNU ls, list the contents of
+ ;; FILE rather than FILE itself.
+ (match (scandir file
+ (match-lambda
+ ((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)))))
(define (ls-command . files)