rejeep / prodigy.el

Manage external services from within Emacs
GNU General Public License v3.0
550 stars 39 forks source link

Run elisp function after process start #99

Closed FrancescElies closed 7 years ago

FrancescElies commented 7 years ago

Hi,

(this is a question not an issue)

I would like to run some small elisp function to copy certain part of the output of a process started with prodigy.

I have the feeling I have to somehow modify prodigy-process-on-output-hook but I am not sure how or if this is the correct place to do it. Could someone give me a hint on how to do that?

Thanks in advance. Best, Francesc

FrancisMurillo commented 7 years ago

Hello dood,

I think :on-output is good enough but the specific process defines how complex the handling would be. How about some more specific context so we can help out?

FrancescElies commented 7 years ago

Hey @FrancisMurillo Sure, thanks!

The idea is the following I want to expose a service to the outside using localtunnel I define the following service:

(prodigy-define-service
  :name "expose session service (5002)"
  :command "lt"
  :args '("--port=5002")
  :tags '(fred-expose)
  :stop-signal 'sigkill
  :kill-process-buffer-on-stop t)

Which produces the following output

your url is: https://kqqvnejclm.localtunnel.me

Then I copy the text and paste it in a different file. This is a repetitive task that I would like to automate.

Best & thanks

FrancescElies commented 7 years ago

on-output sounds good, I'll give it a try

FrancescElies commented 7 years ago

@FrancisMurillo on-output works fine for me, thanks for the help

(prodigy-define-service
  :name "local-tunnel (5002)"
  :command "lt"
  :args '("--port=5002")
  :stop-signal 'sigkill
  :on-output (lambda (&rest args)
               (let ((output (plist-get args :output))
                     (service (plist-get args :service)))
                 (string-match "\\b\\(http.*\\)\\b" output)
                 (kill-new (match-string 1 output))
                 ))
  :kill-process-buffer-on-stop t)