Skip to content

Instantly share code, notes, and snippets.

@Profpatsch
Last active October 19, 2023 11:53
Show Gist options
  • Save Profpatsch/abda97a7b635f876e29f544a26840666 to your computer and use it in GitHub Desktop.
Save Profpatsch/abda97a7b635f876e29f544a26840666 to your computer and use it in GitHub Desktop.
Summary of the Talk “Literate DevOps With Emacs”

link to the video
original essay

General

  • Write in past tense so you don’t have to re-edit when mailing

Running Code

relevant org-mode docs

  • cource code blocks can be created with <s<TAB>
  • C-c C-c executes
  • :exports [code|results|both|none] to export code/
  • :dir <dir> relative path for cwd
  • C-c ' to open code block in its own buffer
  • :tangle <filename> to export code block to file
  • code block attributes can be put in a section property, like
    :PROPERTIES:
    :dir: <relative dir>
    :END:
        
  • name blocks with #+NAME: <name> (shortcut: <n<TAB>)

Code Block Variables

#+BEGIN_SRC :var VARNAME=<something>

Note that something can be the name of a code block, then the value will be the output of that code block.

  • :results table returns a table that can be indexed like table[2,3]

Executing Remote Code

You can use tramp filenames and it will execute remotely

:dir: /scp:my.server.com:mydir

Transforming outputs with another source code block

Create another code block that uses a variable, call this function from the first block with the :post command:

\#+BEGIN_SRC :results value list :post column1(data=*this*)
  bla
\#+END_SRC

\#+BEGIN_SRC elisp :var data="" :results value
  (mapcar 'car data)
\#+END_SRC

Source code blocks that can be used in multiple projects can be put into the org-mode “tower of babel”. (Personal note: It is debatable whether this is a good idea, since now everything depends on your local setup.)

Misc tramp Goodies

Speeding up tramp connections with sessions

Add a :session: <label> property. This also creates a buffer with a remote eshell in it.

Hyperlinks

Use a tramp-style link to reference remote files, which you can then click and edit in-place.

tramp Pipes

Route through multiple hosts like this:
/ssh:bastion.mydomain.com|jumpbox.mydomain.com|dest-host:some-file.org

Also, change protocol:
/ssh:bastion.mydomain.com|sudo:bastion.mydomain.com:/etc/passwd

@dangom
Copy link

dangom commented Mar 21, 2017

First of all, thx a lot for this.
Second, because of (what I think are) some Org 9 syntax changes, the correct procedure to assign code block attributes to a section are now:

:PROPERTIES:
:header-args: :dir <relative dir>
:END:

And to ssh multi-hop:

/ssh:user@domain.com|ssh:user@otherdomain.com:/path/to/whatever

Took me quite a while to find that out, so I'm putting it out here.
Also, things won't work if you have them within a shell SRC_BLOCK. Only within a sh SRC_BLOCK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment