From aafbc96dbd5d1a17a001182d8f725c98c7301f2b Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Wed, 31 Oct 2018 22:30:49 +0100 Subject: [PATCH] rm: Resurrect. * gash/commands/rm.scm: Resurrect. * gash/bournish-commands.scm: Add it. * build-aux/build-guile.sh: Compile it. * .gitignore: Ignore it. --- .gitignore | 1 + build-aux/build-guile.sh | 1 + configure | 1 + gash/bournish-commands.scm | 4 +++ gash/commands/rm.scm | 53 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 60 insertions(+) create mode 100644 gash/commands/rm.scm diff --git a/.gitignore b/.gitignore index 7339ac8..b5fabb3 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ /bin/grep /bin/ls /bin/reboot +/bin/rm /bin/sed /bin/sh /bin/tar diff --git a/build-aux/build-guile.sh b/build-aux/build-guile.sh index dae985e..3fe70b0 100755 --- a/build-aux/build-guile.sh +++ b/build-aux/build-guile.sh @@ -73,6 +73,7 @@ ${srcdest}bin/gash ${srcdest}bin/grep ${srcdest}bin/ls ${srcdest}bin/reboot +${srcdest}bin/rm ${srcdest}bin/sed ${srcdest}bin/tar ${srcdest}bin/wc diff --git a/configure b/configure index b6e7769..93b00c9 100755 --- a/configure +++ b/configure @@ -96,6 +96,7 @@ find grep ls reboot +rm sed tar wc diff --git a/gash/bournish-commands.scm b/gash/bournish-commands.scm index 6ebe234..7ceb818 100644 --- a/gash/bournish-commands.scm +++ b/gash/bournish-commands.scm @@ -38,6 +38,7 @@ #:use-module (gash commands grep) #:use-module (gash commands ls) #:use-module (gash commands reboot) + #:use-module (gash commands rm) #:use-module (gash commands sed) #:use-module (gash commands tar) #:use-module (gash commands wc) @@ -52,6 +53,7 @@ grep-command ls-command reboot-command + rm-command sed-command rm-command wc-command @@ -76,6 +78,7 @@ (define grep-command (wrap-command "grep" grep)) (define ls-command (wrap-command "ls" ls)) (define reboot-command (wrap-command "reboot" reboot)) +(define rm-command (wrap-command "rm" rm)) (define sed-command (wrap-command "sed" sed)) (define tar-command (wrap-command "tar" tar)) (define wc-command (wrap-command "wc" wc)) @@ -90,6 +93,7 @@ ("grep" . ,grep-command) ("ls" . ,ls-command) ("reboot" . ,reboot-command) + ("rm" . ,rm-command) ("sed" . ,sed-command) ("tar" . ,tar-command) ("wc" . ,wc-command) diff --git a/gash/commands/rm.scm b/gash/commands/rm.scm new file mode 100644 index 0000000..0638898 --- /dev/null +++ b/gash/commands/rm.scm @@ -0,0 +1,53 @@ +;;; Gash --- Guile As SHell +;;; Copyright © 2016, 2017 Ludovic Courtès +;;; Copyright © 2016 Efraim Flashner +;;; Copyright © 2017 Ricardo Wurmus +;;; Copyright © 2018 Jan (janneke) Nieuwenhuizen +;;; +;;; 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 . + +;;; Commentary: + +;;; The initial bournish.scm was taken from Guix. + +;;; Code: + +(define-module (gash commands rm) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) + #:use-module (gash shell-utils) + #:export ( + rm + )) + +(define (rm name . args) + (let ((recursive? (or (member "-r" args) + (member "-fr" args) + (member "-rf" args))) + (force? (or (member "-f" args) + (member "-rf" args) + (member "-fr" args))) + (files (filter (negate (cut string-prefix? "-" <>)) args))) + (catch #t + (lambda _ + (if recursive? (for-each delete-file-recursively files) + (for-each delete-file files)) + #t) + (lambda ( . rest) + (or force? + (apply throw rest)))))) + +(define main rm)