link files based on name
linker is a tool for symlinking files based on the name of original file.
linker is supported under python 2.7, 3.3, and 3.4
Thanks to lanshark for adding Python3 support!
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 -m, --move-first move a file from its original location to the repo first, then link it back to its original location -c, --common-target only used with --move-to-target-first, this will move the original file to common, instead of hostname before linking back to its original location
linker makes a few assumptions:
The user “user” keeps their dot files in a repo called “dotfiles” and they want to use linker on a machine called “hostname”.
- /home/user/git/dotfiles - hostname - .vimrc - .vim_colors_color__scheme.vim - crontab_backup.dontlink - _etc_hosts - common - .bashrc
With the command:
linker /home/user/git/dotfiles /home/user
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.
If you already have your files named appropriately, using linker is easy. If you don’t, the naming scheme can be confusing. Using linker -m [-c] will hopefully make this easier.
“User” has a repo “dotfiles” on a machine called “hostname” and wants to add /etc/hosts to the dotfiles repo:
linker -m /home/user/git/dotfiles /etc/hosts
linker will move /etc/hosts to /home/user/git/dotfiles/hostname/_etc_hosts and then link that file back to /etc/hosts:
- /etc/hosts -> /home/user/git/dotfiles/hostname/_etc_hosts
Doing the same, but adding the -c option:
linker -m -c /home/user/git/dotfiles /etc/hosts
linker will move /etc/hosts to /home/user/git/dotfiles/common/_etc_hosts instead of ../hostname/_etc_hosts:
- /etc/hosts -> /home/user/git/dotfiles/common/_etc_hosts
This option was intended to be used one file at a time, and destination must be the full file path.