emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Matt <matt@excalamus.com>
To: "H. Dieter Wilhelm" <dieter@duenenhof-wilhelm.de>
Cc: Michael Powe <powem@ctpowe.net>, emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Re: Shell SRC blocks under Windows
Date: Sat, 05 Feb 2022 17:22:29 -0500	[thread overview]
Message-ID: <17ecbfb46e9.e16df906236239.6523271905911672361@excalamus.com> (raw)
In-Reply-To: <xm46pmo1gvrh.fsf@duenenhof-wilhelm.de>


 ---- On Sat, 05 Feb 2022 10:48:02 -0500 H. Dieter Wilhelm <dieter@duenenhof-wilhelm.de> wrote ----

 > >> Is is it possible to extend org-mode's src blocks with
 > >> org-babel-shell-names to use either MSYS2 or MinGW shells (instead of
 > >> cmd.exe)?  Unfortunately ob-shell.el doesn't guide me further and I
 > >> can't find examples or the respective lisp files on how to define the
 > >> execution functions.
> 
 > Yes, you are right, when using 
 > 
 > > #+begin_src sh
 > 
 > It seems that I'm also running some bash shell! :
 
Yes, it's likely possible to run those shells. Whether or not it will be straight forward or not depends. It's not clear to me what you're trying to do.

First off,  you're looking in the right place. Unfortunately, ob-shell.el can be a little tricky to read.  All the shells are initialized through the =org-babel-shell-initialize= function. This creates a "org-babel-execute:<lang>" for each of the shells given in the =org-babel-shell-names= variable (where <lang> is given by #+begin_src <lang>) . The default shells are: ("sh" "bash" "zsh" "fish" "csh" "ash" "dash" "ksh" "mksh" "posh").   All  execute calls make their way through the God function =org-babel-sh-evaluate= (note: the "sh" in the function name appears to be cruft from when the ob-shell.el module was called "ob-sh.el"; it is not tied specifically to the sh shell).  Technically, which shell is used to evaluate the block depends on the source block parameters used. There are several possible paths.  Unless something weird is being done, however, the block should be evaluated by <lang>.  It looks like you're using a simple one-off shell, not a session or a shebang, so I'll speak to that.

For #+begin_src sh, the block will we evaluated by whatever  "sh" corresponds to in the environment Emacs is running in.  Under the hood, a call is made to the =shell= command and the =shell-file-name= variable gets set to whatever <lang> the block specifies. The an binding happens in =org-babel-shell-initialize=.  So, open a command line environment that would be used to start Emacs and see what "sh" corresponds to:

which sh

That's the shell used by  #+begin_src sh.  Similarly, whatever "which bash" shows is what  #+begin_src bash uses.

This is why it would be surprising that cmd.exe would be used.  

I know that was a lot.  Depending, it may be as simple as updating the =org-babel-shell-names= and rerunning =org-babel-shell-initialize=.  Check the doc strings on those.  Otherwise, I hope this helps ob-shell.el guide you better.

 > But I'm not sure if I'm halfway there with "sh"?  I need to run the
 > following MSYS2 command AND switch between two arguments (for building
 > Emacs).
 > 
 >   \MSYS2\msys2_shell.cmd -mingw64
 > 
 > and
 > 
 >   \MSYS2\msys2_shell.cmd -msys.
 > 
 > How could I achieve this within a src block?

I'm not sure I follow you here.   Can you please describe what you're trying to do and the system you're using (e.g. Windows, GNU/Linux, Haiku) as well the shell used to run the Emacs instance you're doing this in?


  reply	other threads:[~2022-02-05 22:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-04 20:15 Shell SRC blocks under Windows H. Dieter Wilhelm
2022-02-04 21:45 ` Michael Powe
2022-02-05 15:48   ` H. Dieter Wilhelm
2022-02-05 22:22     ` Matt [this message]
2022-02-06 15:46       ` Matt
2022-02-06 17:51         ` H. Dieter Wilhelm
2022-02-07 12:57           ` Matt
2022-02-08  9:47             ` H. Dieter Wilhelm
2022-02-08 22:48               ` Matt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=17ecbfb46e9.e16df906236239.6523271905911672361@excalamus.com \
    --to=matt@excalamus.com \
    --cc=dieter@duenenhof-wilhelm.de \
    --cc=emacs-orgmode@gnu.org \
    --cc=powem@ctpowe.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).