ambrevar: Replace own `sh` functions with cmd:sh alternatives.

master
Pierre Neidhardt 2021-06-09 11:00:48 +02:00
parent 572dd078fc
commit f436e68e53
2 changed files with 10 additions and 35 deletions

View File

@ -3,6 +3,9 @@
(:use #:common-lisp)
(:use #:trivia)
(:import-from #:fof)
(:import-from #:cmd
#:cmd #:$cmd #:cmd! #:cmd? ;; #:cmd& ; `cmd&' is shadowed below.
#:sh #:$sh #:sh& #:sh! #:sh?)
(:import-from #:serapeum #:export-always))
(in-package ambrevar/shell)
(eval-when (:compile-toplevel :load-toplevel :execute)
@ -94,35 +97,6 @@ Return the first non-deleted directory."
;; ;; Use -KILL to fix this?
;; (setf *process-list* nil))
(export-always '*shell*)
(defvar *shell* "sh"
"Default shell to use in `sh' and friends.
Also see `*shell-command-flags*'.")
(export-always '*shell-command-flag*)
(defvar *shell-command-flag* "-c"
"Flag to pass a command string to the `*shell*'.")
(defun format-shell-command (shell-command)
(format nil "~a ~a '~a'"
*shell* *shell-command-flag* shell-command))
(export-always 'sh)
(defun sh (&rest shell-args)
"Wrapper around `cmd:cmd' to execute SHELL-COMMAND in `*shell*'.
SHELL-ARGS are strings that are concatenated before being sent to the shell."
(cmd:cmd (format-shell-command (str:join "" shell-args))))
(export-always 'sh&)
(defun sh& (&rest shell-args)
"Same as `sh' but around `cmd:cmd&'"
(cmd:cmd& (format-shell-command (str:join "" shell-args))))
(export-always '$sh)
(defun $sh (&rest shell-args)
"Same as `sh' but around `cmd:$cmd'"
(cmd:$cmd (format-shell-command (str:join "" shell-args))))
(export-always 'cmd&)
(defun cmd& (cmd) ; TODO: Support (cmd &rest args) lambda list.
"Like `cmd:cmd&' but run and monitor in a shell.
@ -134,6 +108,7 @@ List of background process is maintained in `*process-list*'."
(push handle *process-list*)
handle))
;; See https://github.com/ruricolist/cmd/issues/6 for a discussion.
(export-always 'cmd>)
(defun cmd> (cmd &rest args) ; TODO: "|" is not convenient in CL, use "/" or "-"? See `cmd<>'.
"Like `cmd:cmd&' but return the output as a stream.

View File

@ -2,7 +2,7 @@
(:documentation "Syntax table.")
(:use #:common-lisp)
(:use #:trivia)
(:import-from #:ambrevar/shell)
(:import-from #:cmd)
(:import-from #:serapeum #:export-always))
(in-package ambrevar/syntax)
(eval-when (:compile-toplevel :load-toplevel :execute)
@ -30,14 +30,14 @@
(let ((next-char (read-char stream nil :eof)))
(str:string-case (string next-char)
("#"
(ambrevar/shell:sh (read-until stream #\newline)))
(cmd:sh (read-until stream #\newline)))
("!"
(ambrevar/shell:sh (read-until stream #\newline)))
(cmd:sh (read-until stream #\newline)))
("$"
(ambrevar/shell:$sh (read-until stream #\newline)))
(cmd:$sh (read-until stream #\newline)))
(otherwise
(ambrevar/shell:sh (str:concat (string next-char)
(read-until stream #\newline)))))))
(cmd:sh (str:concat (string next-char)
(read-until stream #\newline)))))))
(export-always 'syntax)
(named-readtables:defreadtable ambrevar/syntax::syntax