#!/usr/bin/env python3 import sys from pathlib import Path home = Path.home().resolve().absolute() dotdir = Path(__file__).parent.resolve().absolute() simple = [ # 'gemrc', "gitconfig", "ideavimrc", "lein", # 'irbrc', # 'nethackrc', # 'spacemacs', "tmux.conf", "vimrc", ] targeted = { "doom": ".doom.d", "fish": ".config/fish", "kitty": ".config/kitty", "alacritty": ".config/alacritty", "i3": ".config/i3", "compton.conf": ".config/compton.conf", "xonsh/rc.xsh": ".xonshrc", "powerline": ".config/powerline" } def deploy(source_name, target_name, dry_run=False): source = dotdir.joinpath(source_name) target = home.joinpath(target_name) if not source.exists(): raise FileNotFoundError( f"Asked to link {source_name}, which doesn't exist in {dotdir}." ) if target.exists(): if target.samefile(source): print(f"{target}->{source} already linked.") return backup_path = target.parent.joinpath(f"{target.name}.bak") print(f"{target} moves to {backup_path}") if not dry_run: target.replace(backup_path) if not target.parent.exists(): print(f"making parent directories of {target}") if not dry_run: target.parent.mkdir(parents=True) print(f"linking {target} to {source}") if not dry_run: target.symlink_to(source) def main(dry_run=True): for source in simple: target = f".{source}" deploy(source, target, dry_run=dry_run) for source, target in targeted.items(): deploy(source, target, dry_run=dry_run) if __name__ == "__main__": try: main(False) except FileNotFoundError as e: print(e) sys.exit(1)