Does anyone know if its possible to send the bash code in a orgmode sh block and run in in a new eshell/term buffer in emacs? for example as a use case i would like to run/eval a code block like this

sudo pacman -Syuu

and have the command execute within emacs in term, eshell etc?

is that possible?


I use the following to send the current line or selected region to the shell associated with a given buffer:

(defun kdm/sh-send-line-or-region () 
(if (use-region-p) 
  (append-to-buffer (get-buffer (directory-shell-buffer-name)) (mark)(point))
  (let (p1 p2)
    (setq p1 (line-beginning-position))
    (setq p2 (line-end-position))
    (append-to-buffer (get-buffer (directory-shell-buffer-name)) p1 p2)
  (let (b)
    (setq b (get-buffer (current-buffer)))
    (switch-to-buffer-other-window (get-buffer (directory-shell-buffer-name)))
    (execute-kbd-macro "\C-m")
    (switch-to-buffer-other-window b)

(global-set-key "\M-s" 'kdm/sh-send-line-or-region)
| improve this answer | |
  • thx. i tried it and get the following error get-buffer: Symbol's function definition is void: directory-shell-buffer-name. any clue? – zeltak Jun 26 '16 at 15:06
  • Not sure, but perhaps that is defined by my shell, which is configured with: (use-package shell-current-directory :bind ("M-S" . shell-current-directory) :config (load-file (expand-file-name "shell.el" user-emacs-directory)) ) – mankoff Jun 26 '16 at 23:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.