#! /usr/bin/env python3 import os import re import shutil import sys DOTS = os.getenv("DOTS", os.getcwd()) def stow(pkg, stow_dir): pkg_path = os.path.join(DOTS, pkg) for root, _, files in os.walk(pkg_path): symlink_dir = root.replace(pkg_path, stow_dir) os.makedirs(symlink_dir, exist_ok=True) for file in files: source = os.path.join(root, file) target = os.path.join(symlink_dir, re.sub("^dot-", ".", file)) if os.path.isfile(target) or os.path.islink(target): os.remove(target) os.symlink(source, target) def get_pkgs(): pkgs = [] for file in os.listdir(DOTS): if file == ".git": continue if os.path.isfile(os.path.join(DOTS, file)): continue pkgs.append(file) return pkgs def get_stow_dir(pkg): return os.path.expanduser({ "home" : "~", "bin" : "~/bin", "config" : "~/.config", "wallpapers" : "~/pics/wallpapers" }.get(pkg, f"~/.config/{pkg}")) if __name__ == "__main__": for pkg in get_pkgs(): stow(pkg, get_stow_dir(pkg))