rmdir: New builtin.
* gash/commands/rmdir.scm: New file. * build-aux/build-guile.sh: Compile it. * configure: Create script. * gash/bournish-commands.scm (rmdir-command): New variable. (%bournish-commands): Add it. * gash/shell-utils.scm (rmdir-p): New function.
This commit is contained in:
parent
f62e6e99a7
commit
45479fc651
|
@ -12,6 +12,7 @@
|
|||
/bin/mkdir
|
||||
/bin/reboot
|
||||
/bin/rm
|
||||
/bin/rmdir
|
||||
/bin/sed
|
||||
/bin/sh
|
||||
/bin/tar
|
||||
|
|
|
@ -59,6 +59,7 @@ ${srcdest}gash/commands/ls.scm
|
|||
${srcdest}gash/commands/mkdir.scm
|
||||
${srcdest}gash/commands/reboot.scm
|
||||
${srcdest}gash/commands/rm.scm
|
||||
${srcdest}gash/commands/rmdir.scm
|
||||
${srcdest}gash/commands/sed.scm
|
||||
${srcdest}gash/commands/tar.scm
|
||||
${srcdest}gash/commands/wc.scm
|
||||
|
@ -78,6 +79,7 @@ ${srcdest}bin/ls
|
|||
${srcdest}bin/mkdir
|
||||
${srcdest}bin/reboot
|
||||
${srcdest}bin/rm
|
||||
${srcdest}bin/rmdir
|
||||
${srcdest}bin/sed
|
||||
${srcdest}bin/tar
|
||||
${srcdest}bin/wc
|
||||
|
|
|
@ -80,6 +80,7 @@
|
|||
(define mkdir-command (wrap-command "mkdir" mkdir))
|
||||
(define reboot-command (wrap-command "reboot" reboot'))
|
||||
(define rm-command (wrap-command "rm" rm))
|
||||
(define rmdir-command (wrap-command "rmdir" rmdir))
|
||||
(define sed-command (wrap-command "sed" sed))
|
||||
(define tar-command (wrap-command "tar" tar))
|
||||
(define wc-command (wrap-command "wc" wc))
|
||||
|
@ -96,6 +97,7 @@
|
|||
("mkdir" . ,mkdir)
|
||||
("reboot" . ,reboot-command)
|
||||
("rm" . ,rm-command)
|
||||
("rmdir" . ,rmdir-command)
|
||||
("sed" . ,sed-command)
|
||||
("tar" . ,tar-command)
|
||||
("wc" . ,wc-command)
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
;;; Gash -- Guile As SHell
|
||||
;;; Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
;;;
|
||||
;;; This file is part of Gash.
|
||||
;;;
|
||||
;;; Gash is free software; you can redistribute it and/or modify it
|
||||
;;; under the terms of the GNU General Public License as published by
|
||||
;;; the Free Software Foundation; either version 3 of the License, or (at
|
||||
;;; your option) any later version.
|
||||
;;;
|
||||
;;; Gash is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
;;; WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
;;; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
;;; details.
|
||||
;;;
|
||||
;;; You should have received a copy of the GNU General Public License
|
||||
;;; along with Gash. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;;; Code:
|
||||
|
||||
(define-module (gash commands rmdir)
|
||||
#:use-module (ice-9 getopt-long)
|
||||
#:use-module (ice-9 match)
|
||||
#:use-module (ice-9 receive)
|
||||
#:use-module (ice-9 regex)
|
||||
|
||||
#:use-module (srfi srfi-1)
|
||||
#:use-module (srfi srfi-9 gnu)
|
||||
#:use-module (srfi srfi-26)
|
||||
|
||||
#:use-module (gash config)
|
||||
#:use-module (gash guix-utils)
|
||||
#:use-module (gash shell-utils)
|
||||
|
||||
#:export (
|
||||
rmdir
|
||||
))
|
||||
|
||||
(define (rmdir . args)
|
||||
(let* ((option-spec
|
||||
'((help (single-char #\h))
|
||||
(parents (single-char #\p))
|
||||
(version (single-char #\V))))
|
||||
(options (getopt-long args option-spec))
|
||||
(files (option-ref options '() '()))
|
||||
(parents? (option-ref options 'parents #f))
|
||||
(help? (option-ref options 'help #f))
|
||||
(version? (option-ref options 'version #f))
|
||||
(files (option-ref options '() '()))
|
||||
(usage? (and (not help?) (null? files))))
|
||||
(cond (version? (format #t "rmdir (GASH) ~a\n" %version) (exit 0))
|
||||
((or help? usage?) (format (if usage? (current-error-port) #t)
|
||||
"\
|
||||
Usage: rmdir [OPTION]... DIRECTORY...
|
||||
Remove the DIRECTORY(ies), if they are empty.
|
||||
|
||||
Options:
|
||||
--help display this help and exit
|
||||
-p, --parents remove DIRECTORY and its ancestors; e.g., 'rmdir -p a/b/c' is
|
||||
similar to 'rmdir a/b/c a/b a'
|
||||
--version output version information and exit
|
||||
|
||||
")
|
||||
(exit (if usage? 2 0)))
|
||||
(else
|
||||
(if parents? (for-each rmdir-p files)
|
||||
(for-each rmdir files))))))
|
||||
|
||||
(define main rmdir)
|
|
@ -70,6 +70,7 @@
|
|||
grep-match-column
|
||||
grep-match-end-column
|
||||
mkdir-p
|
||||
rmdir-p
|
||||
multi-opt
|
||||
|
||||
directory-exists?
|
||||
|
@ -270,6 +271,14 @@ transferred and the continuation of the transfer as a thunk."
|
|||
(apply throw args))))))
|
||||
(() #t))))
|
||||
|
||||
(define (rmdir-p dir)
|
||||
"Remove directory DIR and all its ancestors."
|
||||
(rmdir dir)
|
||||
(let loop ((dir (dirname dir)))
|
||||
(when (not (equal? dir "."))
|
||||
(rmdir dir)
|
||||
(loop (dirname dir)))))
|
||||
|
||||
(define (file-exists?* file)
|
||||
"Like 'file-exists?' but emits a warning if FILE is not accessible."
|
||||
(catch 'system-error
|
||||
|
|
Loading…
Reference in New Issue