aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build-app.lisp12
-rw-r--r--src/lib.lisp29
2 files changed, 28 insertions, 13 deletions
diff --git a/build-app.lisp b/build-app.lisp
index f387116..7da683b 100644
--- a/build-app.lisp
+++ b/build-app.lisp
@@ -50,7 +50,13 @@ my1337pw.")
(group (:header "RUNNING ONELINERS")
(text :contents "Runs the Nth search result with possible arguments ARGS.")
(flag :long-name "clip"
- :description "Put oneliner into clipboard instead of running it."))
+ :description "Put oneliner into clipboard instead of running it.")
+ (lispobj :long-name "timeout"
+ :argument-type :optional
+ :argument-name "SECONDS"
+ :default-value 1.0
+ :typespec 'float
+ :description "How long to wait for output before giving up."))
(text :contents " ")
(group (:header "Help")
(flag :long-name "explain"
@@ -158,7 +164,9 @@ than the users."
;; (cli::make-alias-for-item hist-number (second arguments)))
(t
- (cli::run-item hist-number (rest arguments) (getopt :long-name "clip"))))
+ (cli::run-item hist-number (rest arguments)
+ :force-clip (getopt :long-name "clip")
+ :timeout (getopt :long-name "timeout"))))
(uiop:quit))
;; otherwise search for oneliners
(cli::search-for-oneliners arguments
diff --git a/src/lib.lisp b/src/lib.lisp
index 3df4006..e81c7af 100644
--- a/src/lib.lisp
+++ b/src/lib.lisp
@@ -13,6 +13,8 @@
(defvar *config* nil
"A configuration plist")
+(defvar *ol-output-timeout* 0.8)
+
(defun valid-config-p (config)
(and (listp config)
(evenp (length config))
@@ -224,9 +226,10 @@ the directories that appear in the value of that variable."
(handle-run-oneliner oneliner (or force-clip (equalp runstyle "manual"))))))
-(defun run-item (item-number args &optional force-clip)
- (with-cached-result (ol item-number)
- (bind-vars-and-run-oneliner ol args force-clip)))
+(defun run-item (item-number args &key force-clip (timeout nil timeout-p))
+ (let ((*ol-output-timeout* (if timeout-p timeout *ol-output-timeout*)))
+ (with-cached-result (ol item-number)
+ (bind-vars-and-run-oneliner ol args force-clip))))
(defun valid-oneliner-string-p (string)
(and (not (find #\newline string))
@@ -495,13 +498,16 @@ have passed or CHECK returns non-nil."
for ,var = (progn ,@check)
when ,var
return ,var
- do (sleep ,poll-every))))
+ do (sleep ,poll-every)
+ finally (return nil))))
+
+
(defun run-with-shell
(command
&key
(shell-name (parent-process-name))
- (await-output-p 0.8)
+ (await-output-p *ol-output-timeout*)
(output-stream *standard-output*))
"run COMMAND, a string, in a fresh shell environment, initialized
with SHELL-NAME. The output from the command read line by line and is
@@ -512,10 +518,11 @@ printed to OUTPUT-STREAM. "
(shell-output (uiop:process-info-output shell)))
(write-line command shell-input)
(finish-output shell-input)
- (when await-output-p
- (wait-until (:timeout await-output-p :poll-every 0.005)
- (listen shell-output))
- (loop while (listen shell-output)
- do (princ (read-line shell-output) output-stream)
- (terpri output-stream))))))
+ (if (and await-output-p
+ (wait-until (:timeout await-output-p :poll-every 0.005)
+ (listen shell-output)))
+ (loop while (listen shell-output)
+ do (princ (read-line shell-output) output-stream)
+ (terpri output-stream))
+ (format t "Timed out waiting for output. Try a longer --timeout.~%")))))