I’m claiming a moral victory for my sanity here…..
As a die hard vi user Emacs occasionally confuses me, I’m happy to admit that. Many a time I’ve pressed
:wq instead of
C-x C-s when it comes to saving files.
Thing is Emacs has loads of goodies that I never get to quite try out. Org mode being able to run scripts and stuff is one of them. Curiosity has now given way to requirement so it was a wrestling match to get it working (and reading the documentation did help…. I admit). There’s probably better ways to do this but it worked for me.
Installing Org mode
Open your init.el file and add the following line:
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t)
I’m assuming that you’ve already got
(require 'package) in your init.el file, if you don’t then add that above the add-to-list line.
Open your Emacs, you now need to install the org package and org-contrib package.
You will see org and org-contrib listed (mine are at the top). Install them both, click on the title then click “Install”. Emacs will output a load of stuff but all is normally well. With that done we can now make sure that we can run bash from within Org mode.
Enabling Bash within Emacs
Open your init.el file again. You will now add the org-babel command to load the shell so it can be called from your org file. I usually add this stuff at the bottom of my init file.
(org-babel-do-load-languages 'org-babel-load-languages '((shell . t)))
Save the file and restart Emacs.
Testing within Org mode.
So far so good, now to test.
Either open an org mode file or create one. Now add the following:
#+BEGIN_SRC bash echo 'this is a test' #+END_SRC
Then evaluate the output by using C-c C-c and you will be prompted
Evaluate this bash code block on your system? Respond with
Look at your org file again and you should see the output.
#+BEGIN_SRC bash echo 'this is a test' #+END_SRC #+RESULTS: : this is a test
That’s good enough for me and now I have notes on how to get it working on my work machine tomorrow morning (I’ll forget if I don’t write it down).