feat: dump

This commit is contained in:
Jozef Steinhübl 2024-08-08 12:28:10 +02:00
parent 2ec630fdbf
commit 67a6b1ec42
No known key found for this signature in database
GPG key ID: E6BC90C91973B08F
4 changed files with 41 additions and 7 deletions

View file

@ -1,2 +1,18 @@
def dump(): from glob import glob
from os.path import expanduser, isdir
from os import mkdir
from shutil import copy2
import shutil
def dump(stuff: list[str]):
for pattern in stuff:
expand = expanduser(pattern)
for path in glob(expand, recursive=True):
normalized_path = path.removeprefix(expanduser("~/"))
if isdir(normalized_path):
mkdir(normalized_path)
else:
shutil.copy2(path, normalized_path)
exit(1) exit(1)

View file

@ -1,2 +1,2 @@
def sync(): def sync(stuff: list[str]):
exit(1) exit(1)

15
common/util.py Normal file
View file

@ -0,0 +1,15 @@
import re
def expand(pattern: str) -> list[str]:
match = re.search(r'\{([^{}]*)\}', pattern)
if not match:
return [pattern]
pre, post = pattern[:match.start()], pattern[match.end():]
options = match.group(1).split(',')
expanded_patterns = []
for option in options:
expanded_patterns.extend(expand(pre + option + post))
return expanded_patterns

13
goog
View file

@ -5,12 +5,15 @@ import sys
from common.dump import dump from common.dump import dump
from common.sync import sync from common.sync import sync
from common.util import expand
stuff = { stuff: list[str] = [
"~/.config/{kitty,nvim,openbox,pipewire,tint2,zed}", *expand("~/.config/{kitty,nvim,openbox,pipewire,tint2,zed}/**"),
"~/.themes", "~/.themes/**",
"~/.local/bin/{yarn}" *expand("~/.local/bin/{yarn}"),
} "~/.bashrc",
"~/.xbindkeysrc"
]
options, _ = getopt(sys.argv[1:], "ds", ["dump", "sync"]) options, _ = getopt(sys.argv[1:], "ds", ["dump", "sync"])