Intro to Org Babel TangleApril 21, 2019
For this blog, I'll use my
exports.sh bash script as an example. I use this file to make sure my
$TERM environment variables are set correctly.
Everything below the break is copied over (with some minor editorialization) from my actual
exports.org file. And since you can author gatsby content withorg markdown, I was able to just copy over the contents whole cloth.
To see the exact file I used for this post, see the raw text for this file, but don't forget that viewing org files from emacs is more pleasant experience than looking at the raw file.
This file should be sourced as soon as possible, since we want all child processes to have access to these exported variables.
# This is effectively a compiled file. The source can be found in # ~/programming/dotfiles/dotfiles/exports.org
Since we symlink all of our scripts to
~/.local/bin, we want to make sure that they are visible.
We also want to make sure that cargo bin is on our path since many of our executables end up there.
In order for emacs to have 24-bit color in terminal mode, we need a combination of our
terminfo entry and to set our term to be
And speaking of editor, we want our editor to be emacsclient. The
t flag opens a new Emacs frame on the current terminal. and the =-a ""= opens emacs in daemon mode, then connects to it.
export EDITOR='emacsclient -t -a ""'
We want to have pretty dircolors as well. This will make sure that happens.
eval "$(dircolors ~/programming/dotfiles/dotfiles/.dircolors)"
After tangling the above source block, we're left with the following.
#!/bin/bash # This is effectively a compiled file. The source can be found in # ~/programming/dotfiles/dotfiles/exports.org export PATH="$PATH":~/.local/bin export PATH="$HOME/.cargo/bin:$PATH" export TERM=xterm-24bits export EDITOR='emacsclient -t -a ""' eval "$(dircolors ~/programming/dotfiles/dotfiles/.dircolors)"
This is a simple example, but it shows the expressive power of org-bable-tangle. By creating files this way, I feel more encouraged to add in prose, explanations, and links to explain why I'm doing something. This is especially useful for dotfiles since I often go months or years without making changes to them. By having explanations of why I'm doing something, it's much easier for me to come back later and understand what's going on.