2023-08-21 09:56:16 +00:00
|
|
|
#! /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)
|
|
|
|
|
2024-12-13 22:42:18 +00:00
|
|
|
for root, _, files in os.walk(pkg_path):
|
2023-08-21 09:56:16 +00:00
|
|
|
symlink_dir = root.replace(pkg_path, stow_dir)
|
2024-12-13 22:42:18 +00:00
|
|
|
|
|
|
|
os.makedirs(symlink_dir, exist_ok=True)
|
2023-08-21 09:56:16 +00:00
|
|
|
|
|
|
|
for file in files:
|
|
|
|
source = os.path.join(root, file)
|
|
|
|
target = os.path.join(symlink_dir, re.sub("^dot-", ".", file))
|
|
|
|
|
2023-08-22 12:49:12 +00:00
|
|
|
if os.path.isfile(target) or os.path.islink(target):
|
2023-08-21 09:56:16 +00:00
|
|
|
os.remove(target)
|
|
|
|
|
|
|
|
os.symlink(source, target)
|
|
|
|
|
|
|
|
def get_pkgs():
|
|
|
|
pkgs = []
|
|
|
|
|
2024-12-13 22:42:18 +00:00
|
|
|
for file in os.listdir(DOTS):
|
|
|
|
if file == ".git":
|
|
|
|
continue
|
|
|
|
|
|
|
|
if os.path.isfile(os.path.join(DOTS, file)):
|
|
|
|
continue
|
|
|
|
|
|
|
|
pkgs.append(file)
|
2023-08-21 09:56:16 +00:00
|
|
|
|
|
|
|
return pkgs
|
|
|
|
|
|
|
|
def get_stow_dir(pkg):
|
|
|
|
return os.path.expanduser({
|
2023-08-23 00:00:50 +00:00
|
|
|
"home" : "~",
|
|
|
|
"bin" : "~/bin",
|
|
|
|
"config" : "~/.config",
|
|
|
|
"wallpapers" : "~/pics/wallpapers"
|
2023-08-21 09:56:16 +00:00
|
|
|
}.get(pkg, f"~/.config/{pkg}"))
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
for pkg in get_pkgs():
|
|
|
|
stow(pkg, get_stow_dir(pkg))
|