warbo-utilities: d909ff9a9d5262253d42c500e48a6fbaed4ffb17
1: #!/usr/bin/env python3
2: """To make maintaining, backing up and syncing configuration files easier, we
3: keep them in a git repository and make symlinks in the relevant places.
4:
5: This script makes the linking process easier. Run it from your home directory
6: give it the path to your dotfile directory with the '-df' option and optionally
7: the names of dotfiles you want to link.
8:
9: The convention we follow is that everything in the dotfile directory, say
10: "my-dotfiles/foo", should be linked to a correspondingly named file in ~
11: prefixed with a ., say "~/.foo"."""
12:
13: import sys
14: import os
15:
16: # Check our arguments
17: if len(sys.argv) < 3 or '-df' not in sys.argv:
18: print(__doc__)
19: sys.exit()
20:
21: dotfile_dir = sys.argv[sys.argv.index('-df') + 1]
22: files = list(filter(lambda f: f != '-df' and f != dotfile_dir,
23: sys.argv[1:]))
24:
25: # If we've not been given any files, use everything
26: if len(files) == 0:
27: files = os.listdir(dotfile_dir)
28:
29: # Prefix filenames to get full paths
30: dotfiles = map(lambda f: (dotfile_dir + '/' + f, '.' + f), files)
31:
32: def link(src_dest):
33: """Make a link to the given dotfile."""
34: src, dest = src_dest
35: if not os.path.exists(dest):
36: os.symlink(src, dest)
37:
38: for d in dotfiles:
39: link(d)
Generated by git2html.