From 0a09ab114af631f9763459203014ee5208c9058e Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Fri, 30 Nov 2018 12:26:28 +0100 Subject: [PATCH] mv: New builtin. * gash/commands/mv.scm: New file. * gash/bournish-commands.scm: Use it. * build-aux/build-guile.sh: Compile it. * configure: Wrap it. * .gitignore: Ignore it. --- .gitignore | 2 ++ build-aux/build-guile.sh | 2 ++ configure | 1 + gash/bournish-commands.scm | 10 ++++++-- gash/commands/mkdir.scm | 8 +++---- gash/commands/mv.scm | 47 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 gash/commands/mv.scm diff --git a/.gitignore b/.gitignore index 53c658d..c77a12f 100644 --- a/.gitignore +++ b/.gitignore @@ -12,12 +12,14 @@ /bin/grep /bin/ls /bin/mkdir +/bin/mv /bin/reboot /bin/rm /bin/rmdir /bin/sed /bin/sh /bin/tar +/bin/touch /bin/wc /bin/which /.config.make diff --git a/build-aux/build-guile.sh b/build-aux/build-guile.sh index ff32da8..18cc57a 100755 --- a/build-aux/build-guile.sh +++ b/build-aux/build-guile.sh @@ -66,6 +66,7 @@ ${srcdest}gash/commands/find.scm ${srcdest}gash/commands/grep.scm ${srcdest}gash/commands/ls.scm ${srcdest}gash/commands/mkdir.scm +${srcdest}gash/commands/mv.scm ${srcdest}gash/commands/reboot.scm ${srcdest}gash/commands/rm.scm ${srcdest}gash/commands/rmdir.scm @@ -89,6 +90,7 @@ ${srcdest}bin/gash ${srcdest}bin/grep ${srcdest}bin/ls ${srcdest}bin/mkdir +${srcdest}bin/mv ${srcdest}bin/reboot ${srcdest}bin/rm ${srcdest}bin/rmdir diff --git a/configure b/configure index 7e647e0..9a12bb6 100755 --- a/configure +++ b/configure @@ -102,6 +102,7 @@ find grep ls mkdir +mv reboot rm rmdir diff --git a/gash/bournish-commands.scm b/gash/bournish-commands.scm index e3ac04c..440effe 100644 --- a/gash/bournish-commands.scm +++ b/gash/bournish-commands.scm @@ -39,6 +39,8 @@ #:use-module (gash commands find) #:use-module (gash commands grep) #:use-module (gash commands ls) + #:use-module (gash commands mkdir) + #:use-module (gash commands mv) #:use-module (gash commands reboot) #:use-module (gash commands rm) #:use-module (gash commands sed) @@ -57,6 +59,8 @@ find-command grep-command ls-command + mkdir-command + mv-command reboot-command rm-command sed-command @@ -86,7 +90,8 @@ (define find-command (wrap-command "find" find)) (define grep-command (wrap-command "grep" grep)) (define ls-command (wrap-command "ls" ls)) -(define mkdir-command (wrap-command "mkdir" mkdir)) +(define mkdir-command (wrap-command "mkdir" mkdir')) +(define mv-command (wrap-command "mv" mv)) (define reboot-command (wrap-command "reboot" reboot')) (define rm-command (wrap-command "rm" rm)) (define rmdir-command (wrap-command "rmdir" rmdir)) @@ -106,7 +111,8 @@ ("find" . ,find-command) ("grep" . ,grep-command) ("ls" . ,ls-command) - ("mkdir" . ,mkdir) + ("mkdir" . ,mkdir-command) + ("mv" . ,mv-command) ("reboot" . ,reboot-command) ("rm" . ,rm-command) ("rmdir" . ,rmdir-command) diff --git a/gash/commands/mkdir.scm b/gash/commands/mkdir.scm index aca721e..c798592 100644 --- a/gash/commands/mkdir.scm +++ b/gash/commands/mkdir.scm @@ -35,10 +35,10 @@ #:use-module (gash shell-utils) #:export ( - mkdir + mkdir' )) -(define (mkdir . args) +(define (mkdir' . args) (let* ((option-spec '((help (single-char #\h)) (mode (single-char #\m) (value #t)) @@ -67,8 +67,8 @@ Options: ") (exit (if usage? 2 0))) (else - (let ((mode (if mode (umask (chmodifiers->mode (parse-modifiers mode))) + (let ((mode (if mode (umask (chmodifiers->mode (parse-chmodifiers mode))) #o755))) (for-each (if parents? mkdir-p (@ (guile) mkdir)) files)))))) -(define main mkdir) +(define main mkdir') diff --git a/gash/commands/mv.scm b/gash/commands/mv.scm new file mode 100644 index 0000000..5c60c01 --- /dev/null +++ b/gash/commands/mv.scm @@ -0,0 +1,47 @@ +;;; Gash --- Guile As SHell +;;; 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: + +;;; Code: + +(define-module (gash commands mv) + #:use-module (ice-9 match) + #:use-module (srfi srfi-26) + #:use-module (gash config) + #:use-module (gash shell-utils) + #:export ( + mv + )) + +(define (mv name . args) + (match args + ((or "-h" "--help") + (format #t "mv SOURCE... DEST\n")) + ((or "-V" "--version") + (format #t "mv (GASH) ~a\n" %version) (exit 0)) + ((source dest) + (rename-file source dest)) + ((sources ... dest) + (unless (directory-exists? dest) + (error (format #f "mv: target `~a' is not a directory\n" dest))) + (for-each rename-file + sources + (map (cut string-append dest "/" <>) sources))))) + +(define main mv)