mirror of
https://github.com/xHyroM/dotfiles.git
synced 2024-12-22 12:11:07 +01:00
feat: dump
This commit is contained in:
parent
2ec630fdbf
commit
67a6b1ec42
4 changed files with 41 additions and 7 deletions
|
@ -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)
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
def sync():
|
||||
def sync(stuff: list[str]):
|
||||
exit(1)
|
||||
|
|
15
common/util.py
Normal file
15
common/util.py
Normal 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
13
goog
|
@ -5,12 +5,15 @@ import sys
|
|||
|
||||
from common.dump import dump
|
||||
from common.sync import sync
|
||||
from common.util import expand
|
||||
|
||||
stuff = {
|
||||
"~/.config/{kitty,nvim,openbox,pipewire,tint2,zed}",
|
||||
"~/.themes",
|
||||
"~/.local/bin/{yarn}"
|
||||
}
|
||||
stuff: list[str] = [
|
||||
*expand("~/.config/{kitty,nvim,openbox,pipewire,tint2,zed}/**"),
|
||||
"~/.themes/**",
|
||||
*expand("~/.local/bin/{yarn}"),
|
||||
"~/.bashrc",
|
||||
"~/.xbindkeysrc"
|
||||
]
|
||||
|
||||
options, _ = getopt(sys.argv[1:], "ds", ["dump", "sync"])
|
||||
|
||||
|
|
Loading…
Reference in a new issue