The Irreal blog has recently published a post about Managing dotfiles with
Org. The idea is simple: Put your configuration files and other scripts
in a central (version controlled) place and use Emacs to create the “real files”
based on the content of your org file.
Here’s a short example:
#+BEGIN_SRC conf :tangle "~/.gitconfig" :padline no
email = firstname.lastname@example.org
name = Max Mustermann
showUntrackedFiles = all
lg = log --color --graph --oneline --decorate --abbrev-commit
#+BEGIN_SRC fundamental :tangle "~/.gitmessage" :padline no
# * Why was this change necessary?
# * How does it address the problem?
# * Are there any side effects?
# * What other options did you consider?
#+BEGIN_SRC sh :tangle "~/bin/my-hello" :shebang "#!/bin/bash" :mkdirp yes
set -euo pipefail
Executing the Emacs function
(org-babel-tangle) will create three files:
- Note: The tangling function will (based on the shebang property) make
this script executable. So there’s no need to call
Oh and yes, I can use the same solution on Windows and on Linux. Dealing with
configuration or code in org-mode is also delightful: I can narrow the buffer to
only show a specific file and I’ll even get real syntax highlighting.
One last trick, just for fun:
(org-babel-tangle) can be called via the command
emacs --batch -l org --eval '(org-babel-tangle-file "foo.org")'