dirname: New builtin.

* gash/commands/dirname.scm: New file.
* build-aux/build-guile.sh: Compile it.
* configure: Create script.
* gash/bournish-commands.scm (dirname-command): New variable.
(%bournish-commands): Add it.
This commit is contained in:
Jan Nieuwenhuizen 2018-11-05 20:24:54 +01:00
parent e8b56af461
commit f014281c29
5 changed files with 79 additions and 0 deletions

1
.gitignore vendored
View File

@ -5,6 +5,7 @@
/bin/chmod
/bin/compress
/bin/cp
/bin/dirname
/bin/find
/bin/gash
/bin/grep

View File

@ -53,6 +53,7 @@ ${srcdest}gash/commands/cat.scm
${srcdest}gash/commands/chmod.scm
${srcdest}gash/commands/compress.scm
${srcdest}gash/commands/cp.scm
${srcdest}gash/commands/dirname.scm
${srcdest}gash/commands/find.scm
${srcdest}gash/commands/grep.scm
${srcdest}gash/commands/ls.scm
@ -73,6 +74,7 @@ ${srcdest}bin/cat
${srcdest}bin/chmod
${srcdest}bin/compress
${srcdest}bin/cp
${srcdest}bin/dirname
${srcdest}bin/find
${srcdest}bin/gash
${srcdest}bin/grep

1
configure vendored
View File

@ -93,6 +93,7 @@ cat
chmod
compress
cp
dirname
find
grep
ls

View File

@ -34,6 +34,7 @@
#:use-module (gash commands cat)
#:use-module (gash commands compress)
#:use-module (gash commands cp)
#:use-module (gash commands dirname)
#:use-module (gash commands find)
#:use-module (gash commands grep)
#:use-module (gash commands ls)
@ -50,6 +51,7 @@
cat-command
compress-command
cp-command
dirname-command
find-command
grep-command
ls-command
@ -75,6 +77,7 @@
(define cat-command (wrap-command cat "cat"))
(define compress-command (wrap-command "compress" compress))
(define cp-command (wrap-command "cp" cp))
(define dirname-command (wrap-command "dirname" dirname))
(define find-command (wrap-command "find" find))
(define grep-command (wrap-command "grep" grep))
(define ls-command (wrap-command "ls" ls))
@ -93,6 +96,7 @@
("cat" . ,cat-command)
("compress" . ,compress-command)
("cp" . ,cp-command)
("dirname" . ,dirname-command)
("find" . ,find-command)
("grep" . ,grep-command)
("ls" . ,ls-command)

71
gash/commands/dirname.scm Normal file
View File

@ -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 dirname)
#: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 (
dirname
))
(define (dirname . args)
(let* ((option-spec
'((help (single-char #\h))
(version (single-char #\V))
(zero (single-char #\z))))
(options (getopt-long args option-spec))
(help? (option-ref options 'help #f))
(version? (option-ref options 'version #f))
(files (option-ref options '() '()))
(zero? (option-ref options 'zero #f))
(usage? (and (not help?) (null? files))))
(cond (version? (format #t "dirname (GASH) ~a\n" %version) (exit 0))
((or help? usage?) (format (if usage? (current-error-port) #t)
"\
Usage: dirname [OPTION] FILE...
Output each NAME with its last non-slash component and trailing slashes
removed; if NAME contains no /'s, output '.' (meaning the current directory).
Options:
--help display this help and exit
--version output version information and exit
-z, --zero end each output line with NUL, not newline
")
(exit (if usage? 2 0)))
(else
(for-each (lambda (file)
(display ((@ (guile) dirname) file))
(if zero? (display #\nul) (newline)))
files)))))
(define main dirname)