diff options
author | jao <jao@gnu.org> | 2022-09-02 16:39:38 +0100 |
---|---|---|
committer | jao <jao@gnu.org> | 2022-09-02 16:39:38 +0100 |
commit | 6a64ae46206bfcb3fde1780126d59229793fa94c (patch) | |
tree | 41c63eed52a01366e4288d85c6f7c14875887b91 /lib/eos | |
parent | 6ce5f612c74f4ab3e64c6d372219b4ee45489104 (diff) | |
download | elibs-6a64ae46206bfcb3fde1780126d59229793fa94c.tar.gz elibs-6a64ae46206bfcb3fde1780126d59229793fa94c.tar.bz2 |
jao-shell improvements
Diffstat (limited to 'lib/eos')
-rw-r--r-- | lib/eos/jao-shell.el | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/lib/eos/jao-shell.el b/lib/eos/jao-shell.el index ff1c160..86bf46b 100644 --- a/lib/eos/jao-shell.el +++ b/lib/eos/jao-shell.el @@ -24,25 +24,29 @@ ;;; Code: -(defun jao-shell--quote (x) (shell-quote-argument (format "%s" x))) - -;;;###autoload (defun jao-shell-cmd-lines (cmd &rest args) - (let ((cmd (concat cmd " " (mapconcat #'jao-shell--quote args " ")))) + (let ((cmd (concat cmd " " (combine-and-quote-strings args)))) (split-string (shell-command-to-string cmd) "\n" t))) -;;;###autoload (defun jao-shell-string (cmd &rest args) (string-trim (or (car (apply #'jao-shell-cmd-lines cmd args)) ""))) -;;;###autoload -(defun jao-shell-exec (command) +(defun jao-shell-exec (command &optional wait) (interactive (list (read-shell-command "$ " (if current-prefix-arg (cons (concat " " (buffer-file-name)) 0) "")))) - (start-process-shell-command command nil command)) + (if wait + (call-process-shell-command command) + (start-process-shell-command command nil command))) + +(defun jao-shell-exec* (command-or-wait &rest args) + (let ((wait (and (not (stringp command-or-wait)) command-or-wait)) + (args (if (stringp command-or-wait) (cons command-or-wait args) args))) + (jao-shell-exec (combine-and-quote-strings args) wait))) + +(defun jao-shell-exec-p (command) (eq 0 (jao-shell-exec command t))) (defmacro jao-shell-def-exec (name &rest args) `(defun ,name (&rest other-args) @@ -52,9 +56,14 @@ "*jao-exec - console*" (string-join (append (list ,@args) other-args) " ")))) -;;;###autoload -(defun jao-shell-running-p (pr) - (not (string-blank-p (shell-command-to-string (concat "pidof " pr))))) +(defun jao-shell-output (cmd handler) + (with-temp-buffer + (call-process-shell-command cmd nil (current-buffer)) + (beginning-of-buffer) + (funcall handler))) + +(defun jao-shell-running-p (pr) (eq 0 (jao-shell-exec* t "pidof" pr))) +(defun jao-shell-kill-p (pr) (eq 0 (jao-shell-exec* t "killall" pr))) (provide 'jao-shell) ;;; jao-shell.el ends here |