;;;; main.lisp -- oneliners.cli entrypoint (defpackage oneliners.cli (:use :cl)) (in-package :oneliners.cli) ;;; 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)))))