diff options
author | Colin Okay <okay@toyful.space> | 2022-03-14 19:36:18 -0500 |
---|---|---|
committer | Colin Okay <okay@toyful.space> | 2022-03-14 19:36:18 -0500 |
commit | 130ae266f51f63ac423a65b17749a4d38dda1018 (patch) | |
tree | 495e848885014b8854f0408f8118daa05ec00bf8 | |
parent | 67c793633bfcd46997155341dd4b1776fb6a6728 (diff) |
Added a --verbose / -v option to RUN
-rw-r--r-- | app/app.lisp | 4 | ||||
-rw-r--r-- | lib/client.lisp | 19 |
2 files changed, 14 insertions, 9 deletions
diff --git a/app/app.lisp b/app/app.lisp index 9b313db..eef9b89 100644 --- a/app/app.lisp +++ b/app/app.lisp @@ -136,6 +136,9 @@ Their meaning is as follows: :default-value 1 :typespec 'integer :description "How many seconds to wait for standard output before giving up.") + (flag :long-name "verbose" + :short-name "v" + :description "Prints a message indicating the oneliner text that is about to be run prior to execution.") (flag :long-name "draft" :description "Indicates that you wish to run a draft of a oneliner identified by IDENTIFIER.")) (group (:header "CLIPPING ONELINERS" :hidden t) @@ -293,6 +296,7 @@ than the users." (:run (help-and-quit-unless "run" id-or-name) (cli:run-item id-or-name (rest args) + :verbose (getopt :long-name "verbose") :timeout (getopt :long-name "timeout") :draftp (getopt :long-name "draft"))) (:clip diff --git a/lib/client.lisp b/lib/client.lisp index 39d60ec..9f34bb5 100644 --- a/lib/client.lisp +++ b/lib/client.lisp @@ -92,14 +92,14 @@ running the body. If such a oneliner can be found." (defvar *ol-output-timeout* 1) -(defun run-item (ident args &key force-clip (timeout nil timeout-p) draftp) +(defun run-item (ident args &key force-clip (timeout nil timeout-p) draftp verbose) "Runs a oneliner identified by IDENT (if available) with arguments ARGS." (let ((ol (if draftp (fetch-draft ident) (the-oneliner ident)))) (when ol (let ((*ol-output-timeout* (if timeout-p timeout *ol-output-timeout*))) - (bind-vars-and-run-oneliner ol args force-clip))))) + (bind-vars-and-run-oneliner ol args force-clip verbose))))) -(defun bind-vars-and-run-oneliner (ol args &optional force-clip) +(defun bind-vars-and-run-oneliner (ol args &optional force-clip verbose) (let* ((oneliner (oneliner-oneliner ol)) (runstyle (oneliner-runstyle ol)) (pos-args (get-positional-arguments ol)) @@ -120,17 +120,18 @@ running the body. If such a oneliner can be found." do (setf oneliner (str:replace-all var (second bound) oneliner))) - (handle-run-oneliner oneliner (or force-clip (equalp runstyle "manual")))))) + (handle-run-oneliner oneliner (or force-clip (equalp runstyle "manual")) verbose)))) -(defun handle-run-oneliner (ol &optional clip) +(defun handle-run-oneliner (ol &optional clip (verbose t)) (if clip (progn (trivial-clipboard:text ol) (format t "Copied oneliner to clipboard~%")) (progn - (format t "Attempting to run:~%") - (princ ol) - (princ #\newline) - (princ #\newline) + (when verbose + (format t "Attempting to run:~%") + (princ ol) + (princ #\newline) + (princ #\newline)) (run-with-shell ol :shell-name (or (shell) "bash") :await-output-p *ol-output-timeout*)))) ;;; ADDING ONELINERS |