help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to send lines of a shell script directly to the shell


From: Uwe Brauer
Subject: Re: how to send lines of a shell script directly to the shell
Date: Thu, 20 Apr 2023 22:12:22 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

>>> "LB" == Leo Butler <Leo.Butler@umanitoba.ca> writes:

> On Sun, Apr 16 2023, Uwe Brauer <oub@mat.ucm.es> wrote:
>>> On Sun, Apr 16, 2023 at 10:53:54AM +0200, Uwe Brauer wrote:
>> 
>>> Ask your Emacs, not Google. Emacs is your friend, Google isn't :)
>> 
>> With a bit better search I obtained
>> 
>> https://stackoverflow.com/questions/6286579/emacs-shell-mode-how-to-send-region-to-shell
>> 
>> Which does what I want

> There are several solutions there, you don't mention which you chose.

This one

(defun sh-send-line-or-region (&optional step)
  (interactive ())
  (let ((proc (get-process "shell"))
        pbuf min max command)
    (unless proc
      (let ((currbuff (current-buffer)))
        (shell)
        (switch-to-buffer currbuff)
        (setq proc (get-process "shell"))
        ))
    (setq pbuff (process-buffer proc))
    (if (use-region-p)
        (setq min (region-beginning)
              max (region-end))
      (setq min (point-at-bol)
            max (point-at-eol)))
    (setq command (concat (buffer-substring min max) "\n"))
    (with-current-buffer pbuff
      (goto-char (process-mark proc))
      (insert command)
      (move-marker (process-mark proc) (point))
      ) ;;pop-to-buffer does not work with save-current-buffer -- bug?
    (process-send-string  proc command)
    (display-buffer (process-buffer proc) t)
    (when step 
      (goto-char max)
      (next-line))
    ))

> Anyhow, I recommend keyboard macros. That is generally much faster than
> any alternative...if I find myself using a keyboard macro repeatedly,
> then I will invest time in finding or writing a better alternative.

Uff, I found this cumbersome



-- 
Warning: Content may be disturbing to some audiences
I strongly condemn Putin's war of aggression against the Ukraine.
I support to deliver weapons to Ukraine's military. 
I support the ban of Russia from SWIFT.
I support the EU membership of the Ukraine. 
https://addons.thunderbird.net/en-US/thunderbird/addon/gmail-conversation-view/

Attachment: smime.p7s
Description: S/MIME cryptographic signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]