2
$\begingroup$

I want to call this zsh alias in a mathematica cell?

my zsh alias is called testAlias

enter image description here

I have tried many mathematica functions and found that ReadList can send strings to my zsh shell (or internal command line anyhow)

Unfortunately alias's don't work.

enter image description here Is there any way I can run testAlias in mathematica?

$\endgroup$
1
  • 1
    $\begingroup$ If I'm not mistaken the process where the alias was defined was closed after the run through ReadList. Check out StartProcess. Then you can use WriteLine[procObj,"testAlias"] and read it back in with ReadString[procObj, EndOfBuffer]. $\endgroup$
    – b3m2a1
    Jun 17, 2017 at 17:21

1 Answer 1

1
$\begingroup$

Oh_My_Zsh, iTerm, Zsh, called from Mathematica Notebook

to help future strugglers here is @b3m2a1's comment expanded into a function which sends commands to the Oh_My_Zsh environment enabling scripting/Automation using mathematica string manipulation.

enter image description here

zshTerminal[commandString_] := Module[
{process},
process = StartProcess[{$SystemShell}];
WriteLine[process, ". ~/.zshrc"];
WriteLine[process, commandString];
WriteLine[process, "exit\n"];
Print[ReadString[process]]
];

zshTerminal["ls"]

enter image description here

zshTerminal["testFunction"]

enter image description here


zshTerminal["testAlias"]
$\endgroup$
1
  • 1
    $\begingroup$ One thing you may want to do is either cache your zsh process to avoid having to spin up a new one each call (just make sure to check it's still running via ProcessStatus before trying to use it) or close it using KillProcess when you're done so you don't get a backlog of ProcessObjects under Processes[]. $\endgroup$
    – b3m2a1
    Jun 17, 2017 at 19:36

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.