link files based on name
linker is a tool for symlinking files based on the name of original file.
Usage: linker.py [options] target destination Options: -h, --help show this help message and exit -i, --interactive Prompt for all changes -v, --verbose Print all changes -d, --dry-run Print all changes, but DON'T DO THEM -x, --exclude-common default is to link files in `hostname` and 'common' dirs. this will only link `hostname` --delete-existing delete existing files instead of moving them to original_name.back
Deterministic File Names
linker makes a few assumptions:
- The git repo (or whatever else the target path happens to be) will have at least one folder in it, which matches the hostname of the machine linker is running on. This allows multiple machine configs to be kept in the same repo.
- If a target file ends with “.dontlink” it should be tracked in the repo, but not linked by linker.
- Underscores (_) in the target file should be replaced with slashes (/) in the symlink. This allows you to keep all the files for a single host in the same directory level of the repo, but be multiple levels deep where the link is made.
- A double underscore in the target file is a literal underscore in the link name.
- A file that starts with an underscore should be linked from /, not from the destination root.
- If a directory named “common” exists at the same level as the hostname directory, those files should be linked, too. (This allows some files to link on all machines in the repo.)
- If a file already exists, it should be backed up (moved to original_name.back), unless you explicity include --delete-existing.
The user “user” keeps their dot files in a repo called “dotfiles” and they want to use linker on a machine called “hostname”.
linker would make the following symlinks:
- /home/user/.bashrc -> /home/user/git/dotfiles/common/.bashrc
- /home/user/.vimrc -> /home/user/git/dotfiles/hostname/.vimrc
- /home/user/vim/colors/color_scheme.vim -> /home/user/git/dotfiles/hostname/.vim_colors_color__scheme.vim
- /etc/hosts -> /home/user/git/dotfiles/hostname/_etc_hosts
Notice crontab_backup.dontlink wasn’t linked anywhere.