ambrevar/shell: Add cmd<>, cmd< and $cmd<.
parent
f0cad5decb
commit
ab9717074a
|
@ -247,7 +247,7 @@ List of background process is maintained in `*process-list*'."
|
|||
handle))
|
||||
|
||||
(export-always 'cmd>)
|
||||
(defun cmd> (cmd &rest args) ; TODO: "|" is not convenient in CL, use "/" or "-"?
|
||||
(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.
|
||||
Return the process handler as second value.
|
||||
Use
|
||||
|
@ -260,6 +260,42 @@ to get the final output as a string."
|
|||
(values (uiop:process-info-output handler)
|
||||
handler)))
|
||||
|
||||
(export-always 'cmd<>)
|
||||
(defun cmd<> (cmd &rest args)
|
||||
"Like `cmd>' but last argument is passed as `:input'.
|
||||
This can be usefully chained, e.g. with arrow macros.
|
||||
Example:
|
||||
|
||||
(->>
|
||||
(cmd> \"cat\" \".../share/hunspell/en_GB-large.dic\")
|
||||
(cmd<> \"sort\")
|
||||
(cmd<> \"uniq\" \"-c\")
|
||||
(cmd<> \"sort\" \"-nr\")
|
||||
(cmd<> \"head\" \"-3\"))"
|
||||
(let* ((butlast-args (butlast args))
|
||||
(last-arg (first (last args)))
|
||||
(handler (apply #'cmd:cmd& cmd (append butlast-args
|
||||
(list :output :stream
|
||||
:input last-arg)))))
|
||||
(values (uiop:process-info-output handler)
|
||||
handler)))
|
||||
|
||||
(export-always 'cmd<)
|
||||
(defun cmd< (cmd &rest args)
|
||||
"Like `cmd<>' but output to standard output."
|
||||
(let* ((butlast-args (butlast args))
|
||||
(last-arg (first (last args))))
|
||||
(apply #'cmd:cmd cmd (append butlast-args
|
||||
(list :input last-arg)))))
|
||||
|
||||
(export-always '$cmd<)
|
||||
(defun $cmd< (cmd &rest args)
|
||||
"Like `cmd<>' but return string."
|
||||
(let* ((butlast-args (butlast args))
|
||||
(last-arg (first (last args))))
|
||||
(apply #'cmd:$cmd cmd (append butlast-args
|
||||
(list :input last-arg)))))
|
||||
|
||||
(export-always 'tee)
|
||||
(defun tee (input-stream)
|
||||
"Return the INPUT-STREAM and its string representation as a second value."
|
||||
|
|
Loading…
Reference in New Issue