Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The page content piping could be done e.g. like this:

  (defun get-buffer-text (&optional buf)
    (nyxt/mode/document:select-all buf)
    (nyxt/mode/document:copy buf)
    (trivial-clipboard:text))

  (define-internal-page cmd-result (&key text) (:title "*Result*")
    (spinneret:with-html-string
      (dolist (line (str:split #\newline text))
        (:p line))))

  (define-command-global buf-text-to-pipe-cmd (&optional buf cmd)
    (let* ((buf (or buf (nyxt:current-buffer)))
           (safe-text (uiop:escape-sh-token (get-buffer-text buf)))
           (cmd (or cmd (prompt1 :prompt "cmd: " :sources 'prompter:raw-source)))
           (cmd-output (uiop:run-program
                        `("bash" "-c" ,(str:concat "echo '" safe-text "' | " cmd))
                        :output :string)))
      (nyxt:buffer-load-internal-page-focus 'cmd-result :text cmd-output)))
And then call the function like C-space buf-text-to-pipe-cmd and specify the commands to pipe to. Output will appear in a new buffer that can be further used as the source for piping.

DOM handling would be a tad more laborous, but you can pick DOM elements from output of nyxt:document-model with CSS selectors using clss:select.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: