1 Here’s how
Emacs 24.x up, Org-Mode 8.x or newer, and Your favourite keyboard.
Open a new file in Emacs, call it
dotfiles.org or whatever you like.
1.2 "Normal" dotfiles
These files directly reside under your home directory. So managing them in Emacs is very straightforward. For ease of organization, you can put files of the same category, e.g. all things related to email, under a heading:
* Email ** Muttrc ** Aliases ** goobookrc
Then, under each subheading, put your files in an src block, like this:
* Email ** Muttrc #+BEGIN_SRC conf :tangle ~/.muttrc #source "/etc/Muttrc" # Not available on OS X source "gpg --batch --passphrase-file ~/.sec/.passphrase --textmode -d ~/.sec/mutt.gpg |" set realname="Haoyang Xu" set sig_dashes ... #+END_SRC
Then if you run
M-x org-babel-tangle , or press
C-c C-v t , the content of the above src block will be written to
$HOME/.muttrc , overwriting the file’s content if it exists already.
Similarly, write each file’s content in an src block under the corresponding subheading:
* Email ** Muttrc ... ** Aliases #+BEGIN_SRC conf :tangle ~/.aliases alias mumon firstname.lastname@example.org #+END_SRC ** goobookrc #+BEGIN_SRC conf :tangle ~/.goobookrc [DEFAULT] # The following are optional, defaults are shown # This file is written by the oauth library, and should be kept secure, # it's like a password to your google contacts. ;oauth_db_filename: ~/.goobook_auth.json # The client secret file is not really secret. ;client_secret_filename: ~/.goobook_client_secret.json ;cache_filename: ~/.goobook_cache ;cache_expiry_hours: 24 ;filter_groupless_contacts: yes #+END_SRC
Now when you invoke
org-babel-tangle , the 3 dotfiles will be written. You can put the .org file under version control, edit the dotfiles within Emacs, and deploy them with one command.
1.3 Dotfiles in a dotdir
For example, you want to manage your SSH config file, which is under
.ssh . Normally it will not be more difficult than the case above. But if you are setting up a new machine and don’t have
.ssh path yet, Org-Mode will complain when you tangle.
In that case, you can write a "magic" line at the beginning of the file:
# -*- eval: (make-directory ".ssh" "~") -*-
Alternatively, you can write an src block before the file content block to run commands that create the directories needed.
#+BEGIN_SRC sh mkdir ~/.ssh #+END_SRC
1.4 Emacs dotfiles
If your are using the good old
init.el to store your Emacs configuration, they are managed in the same manner as the above cases. However, if your configuration are already living in another
.org file, you probably don’t want to put it in an "org" src block in your
dotfile.org . My solution is to put it in a directory under the directory where my
home.org (my dotfile) resides. That makes it a little untidy but I don’t have a better solution right now. Ah, the taste of irony.
1.5 Credentials and secrets
If you are putting your dotfiles online, you need to save dotfiles with passwords/secrets in an encrypted format. Luckily, Emacs has very good encryption/decryption support. You can put things you don’t want others to read into a specific
.org file, and use
epa-encrypt-file to get encrypted file with
.gpg suffix. After that you can delete the clear text
.org file. Next time when you edit the encrypted
.org.gpg file, Emacs will use
gpg-agent to ask for the password, and decrypt it for you.
转载本站任何文章请注明：转载至神刀安全网，谢谢神刀安全网 » Dotfile Management and Documentation with Org-Mode