From dcce2810f970c8cc88515a78abc5b71eaa154f46 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Mon, 27 Feb 2023 09:49:51 -0600 Subject: [PATCH] can clone git repos now --- config.ini | 30 ++++++++++++++++++++---------- prefs/git.py | 24 ++++++++++++++++++++++++ prefs/linker.py | 5 ++++- prefs/resource.py | 3 ++- 4 files changed, 50 insertions(+), 12 deletions(-) create mode 100644 prefs/git.py diff --git a/config.ini b/config.ini index 0e1dc46..18cffbf 100644 --- a/config.ini +++ b/config.ini @@ -17,7 +17,26 @@ files: # [run vim-plugins] # when: host.has('vim') # cmd: vim +PluginInstall +qall -# + +[link-files neovim:windows] +when: host.is_windows and host.has('nvim') +target_root: ~/AppData/Local +files: + nvim/lua + .vim/ftplugin > nvim/ftplugin + .vimrc > nvim/init.vim + Vundle.vim > nvim/bundle/Vundle.vim + +[git packer-posix] +when: not host.is_windows +repo: https://github.com/wbthomason/packer.nvim +target: ~/.local/share/nvim/site/pack/packer/start/packer.nvim + +[git packer-windows] +when: host.is_windows +repo: https://github.com/wbthomason/packer.nvim +target: ~/AppData/Local/nvim-data/site/pack/packer/start/packer.nvim + # [run nvim-plugins] # when: host.has('nvim') # cmd: nvim +PluginInstall +qall @@ -50,15 +69,6 @@ files: nvim/init.vim > .config/nvim/init.vim when: host.is_wsl files: scripts/winmode > bin/winmode -[link-files neovim:windows] -when: host.is_windows and host.has('nvim') -target_root: ~/AppData/Local -files: - nvim/lua - .vim/ftplugin > nvim/ftplugin - .vimrc > nvim/init.vim - Vundle.vim > nvim/bundle/Vundle.vim - packer.nvim > nvim-data/site/pack/packer/start/packer.nvim [link-files vscode:windows] when: host.is_windows and host.has('code') diff --git a/prefs/git.py b/prefs/git.py new file mode 100644 index 0000000..8cd86c9 --- /dev/null +++ b/prefs/git.py @@ -0,0 +1,24 @@ +import subprocess +from pathlib import Path +from . import log + +class Repo: + resource_name = 'git' + + def __init__(self, label, section): + self.label = label or None + self.repo = section['repo'] + self.target = Path(section['target']).expanduser() + + def run(self): + if self.target.exists(): + log.debug("target exists") + if self.target.is_dir(): + log.debug("target is dir") + git_dir = self.target / ".git" + if git_dir.exists() and git_dir.is_dir(): + log.debug("target is git repo") + return + + cmd = ["git", "clone", self.repo, self.target] + subprocess.call(cmd) diff --git a/prefs/linker.py b/prefs/linker.py index 5f06261..866f1b5 100644 --- a/prefs/linker.py +++ b/prefs/linker.py @@ -45,7 +45,10 @@ class Linker: print(f"rm {target_path} (broken symlink)") target_path.unlink() - target_path.symlink_to(source_path) + try: + target_path.symlink_to(source_path) + except PermissionError as e: + print(f"ERROR creating link: {e}") print(f"link {target_path} -> {source_path}") class LinkFiles: diff --git a/prefs/resource.py b/prefs/resource.py index 499ce85..216f15e 100644 --- a/prefs/resource.py +++ b/prefs/resource.py @@ -2,9 +2,10 @@ from .home import Home from .linker import LinkFiles from .cargo import CargoInstall from .run import Run +from . import git class Resource: - resource_types = [Home, LinkFiles, CargoInstall, Run] + resource_types = [Home, LinkFiles, CargoInstall, Run, git.Repo] @classmethod def from_name(cls, name):