emacs-orgmode
[Top][All Lists]
Advanced

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

Re: Shell SRC blocks under Windows


From: Matt
Subject: Re: Shell SRC blocks under Windows
Date: Sat, 05 Feb 2022 17:22:29 -0500
User-agent: Zoho Mail

 ---- 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 via email to

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