Capture dotfiles using org-capture
Since I discovered org mode, I always was balancing between using symlinks and org babel tangle to manage my configuration. Now I'm in point that work related items are org babel managed and system level config is symlinked, because, often tools write back to their files. Another reason why I did not go full on babel was that I don't like workflow:
- found file that requires backup
- copy file
- paste in to org mode
- fill all details
- tangle.
But yesterday I was visited by GNU spirit and she gave mi this org-capture template that reduces adding new file to backup to C-c k (my capture prefix) b (backup) and then tangle that file to original place:
* [[%(project-root (project-current))]] [[%(abbreviate-file-name (org-capture-get :original-file))][%(file-relative-name (org-capture-get :original-file) (project-root (project-current)))]]
- repository :: [[%(project-root (project-current))]]
- file :: [[%(abbreviate-file-name (org-capture-get :original-file))][%(file-relative-name (org-capture-get :original-file) (project-root (project-current)))]]
#+header: :tangle %(abbreviate-file-name (org-capture-get :original-file))
#+begin_src %^{Language|shell|elixir|nix|python|elisp|fundamental|eshell|conf}
%(with-temp-buffer (insert-file-contents (org-capture-get :original-file)) (buffer-string))
#+end_src
I cannot comprehend how simple it is and how I never realized I could do this.
Two think I think would be nice in future:
- if only it can automatically group those captures by project, but thinking of creating project backup capture template and simply refile from capture buffer
- automatic detangle so I can get back changes written by tools to their files, but not all of them support comments and many of them don't patch but dump state to file, so probably unsolvable using build in tools, only by elisp scripting
I'm trying to avoid longer elisp scripting for now 😄
What do you think?