aboutsummaryrefslogtreecommitdiff
path: root/src/main.lisp
diff options
context:
space:
mode:
authorColin Okay <okay@toyful.space>2022-02-11 11:15:29 -0600
committerColin Okay <okay@toyful.space>2022-02-11 11:15:29 -0600
commitb849afd06be6da866a31a0be74d90851c0258134 (patch)
tree1ace066f1999c8cf1099546fb6d304ed03c55252 /src/main.lisp
parent4d2ada0a465583e4b8516aa3f6308fdcb10d79d7 (diff)
added some utilities
Diffstat (limited to 'src/main.lisp')
-rw-r--r--src/main.lisp29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/main.lisp b/src/main.lisp
index 649c140..8d7db60 100644
--- a/src/main.lisp
+++ b/src/main.lisp
@@ -1,5 +1,32 @@
+;;;; main.lisp -- oneliners.cli entrypoint
+
(defpackage oneliners.cli
(:use :cl))
(in-package :oneliners.cli)
-;; blah blah blah.
+;;; UTILITIES
+
+(defun parent-process-name ()
+ "Prints the name of the parent process of the current process."
+ (let ((ppidfile (format nil "/proc/~a/status" (osicat-posix:getppid))))
+ (first (last
+ (ppcre:split "\\s"
+ (with-open-file (input ppidfile)
+ (read-line input)))))))
+
+(defun run-with-shell
+ (command
+ &key
+ (shell-name (parent-process-name))
+ (await-output-p t)
+ (output-stream *standard-output*))
+ (let ((shell
+ (uiop:launch-program shell-name :input :stream :output :stream)))
+ (write-line command (uiop:process-info-input shell))
+ (finish-output (uiop:process-info-input shell))
+ (when await-output-p
+ (loop until (listen (uiop:process-info-output shell)))
+ (loop while (listen (uiop:process-info-output shell))
+ do (princ (read-line (uiop:process-info-output shell)) output-stream)
+ (terpri output-stream)))))
+