Files
dotfiles/meta/install.py

44 lines
1.4 KiB
Python
Raw Permalink Normal View History

2026-01-17 17:44:55 +00:00
import sys
import os
import json
import pathlib
dotfile_dir = sys.argv[1]
home_dir = str(pathlib.Path.home())
def install_component(comp):
print('Installing component: {}...'.format(comp['name']))
2026-01-17 17:44:55 +00:00
comp_dir = os.path.join(dotfile_dir, comp['name'])
if 'link-files' in comp:
link_files = comp['link-files']
for f in link_files:
source_path = os.path.join(comp_dir, f['source'])
if f['source'] == '.':
source_path = comp_dir
2026-01-17 17:44:55 +00:00
dest_path = os.path.join(home_dir, f['dest'])
if not os.path.exists(dest_path):
print(' linking {} -> {}'.format(dest_path, source_path))
os.symlink(source_path, dest_path)
if 'link-dirs' in comp:
link_dirs = comp['link-dirs']
for f in link_dirs:
source_path = os.path.join(comp_dir, f['source'])
if f['source'] == '.':
source_path = comp_dir
2026-01-17 17:44:55 +00:00
dest_path = os.path.join(home_dir, f['dest'])
if not os.path.exists(dest_path):
print(' linking {} -> {}'.format(dest_path, source_path))
os.symlink(source_path, dest_path)
components_path = os.path.join(dotfile_dir, 'meta', 'components.json')
components = None
with open(components_path, 'r') as f:
components = json.load(f)
for comp in components:
install_component(comp)