From 523bfdcdfb3c4d08d8ed1678988948c08e5c7ae2 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sat, 25 Feb 2023 19:22:29 -0600 Subject: [PATCH] this is getting good --- config.ini | 65 ++++++++++++++++++++++----------------- prefs/installer.py | 8 ++--- prefs/resource.py | 3 +- prefs/run.py | 25 +++++++++++++++ windows/install-scoop.ps1 | 2 ++ 5 files changed, 70 insertions(+), 33 deletions(-) create mode 100644 prefs/run.py create mode 100644 windows/install-scoop.ps1 diff --git a/config.ini b/config.ini index 3738e43..496ab9d 100644 --- a/config.ini +++ b/config.ini @@ -1,52 +1,61 @@ -# items in the [home] section are copied into the home directory with the same -# relative location as they appear in the dotfiles repo -[home] -files: - # sync vim plugin directories but not all of .vim - .vim/ftplugin - .vim/pack +[run submodules] +cmd: git submodule init - # individual files to sync +[home bash-prefs] +when: host.has('bash') +files: .bash_profile .bashrc + +[home vim] +when: host.has('vim') +files: + .vim/ftplugin + .vim/pack .vimrc - cargo-config.toml > .cargo/config.toml +[run vim-plugins] +when: host.has('vim') +cmd: vim +PluginInstall +qall +[home cargo] +when: host.has('cargo') +files: cargo-config.toml > .cargo/config.toml -[home posix] -when: not host.is_windows +[home htop] +when: host.has('htop') +files: .config/htop/htoprc -files: - .screenrc - .tmux.conf - .config/lazydocker/config.yml - .config/htop/htoprc +[home lazydocker] +when: host.has('lazydocker') +files: .config/lazydocker/config.yml + +[home screenrc] +when: host.has('screen') +files: .screenrc - nvim/init.vim > .config/nvim/init.vim +[home tmux] +when: host.has('tmux') +files: .tmux.conf +[home posix-nvim] +when: host.has('nvim') and not host.is_windows +files: nvim/init.vim > .config/nvim/init.vim [home wsl] when: host.is_wsl +files: scripts/winmode > bin/winmode -files: - scripts/winmode > bin/winmode - - -[link-files AppData] -when: host.is_windows - +[link-files windows-neovim] +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 - .vim/ftplugin > nvim/ftplugin packer.nvim > nvim-data/site/pack/packer/start/packer.nvim - [cargo-install] crates: just diff --git a/prefs/installer.py b/prefs/installer.py index 416042c..a5f2f55 100644 --- a/prefs/installer.py +++ b/prefs/installer.py @@ -28,14 +28,14 @@ class Installer: return parser def run(self): - resources = [] for name in self.config.sections(): section = self.config[name] if self.when(section): r = Resource.from_section(name, section) - resources.append(r) - for r in resources: - r.run() + print(f"RUN [{name}]") + r.run() + else: + print(f"SKIP [{name}]") def when(self, section): if clause := section.get('when', None): diff --git a/prefs/resource.py b/prefs/resource.py index 2451ef9..499ce85 100644 --- a/prefs/resource.py +++ b/prefs/resource.py @@ -1,9 +1,10 @@ from .home import Home from .linker import LinkFiles from .cargo import CargoInstall +from .run import Run class Resource: - resource_types = [Home, LinkFiles, CargoInstall] + resource_types = [Home, LinkFiles, CargoInstall, Run] @classmethod def from_name(cls, name): diff --git a/prefs/run.py b/prefs/run.py new file mode 100644 index 0000000..6c53464 --- /dev/null +++ b/prefs/run.py @@ -0,0 +1,25 @@ +import subprocess +import os +import shutil +from . import host + +class Run: + resource_name = 'run' + + def __init__(self, label, section): + self.label = label or None + self.cmd = section.get('cmd', '').split() + self.cwd = section.get('cwd', host.dotfiles_root) + self.shell = section.get('shell', False) + + def run(self): + kwargs = { + "cwd": self.cwd, + "stdout": subprocess.PIPE, + "text": True, + "shell": self.shell, + } + with subprocess.Popen(self.cmd, **kwargs) as proc: + line = proc.stdout.read() + if line: + print(line) diff --git a/windows/install-scoop.ps1 b/windows/install-scoop.ps1 new file mode 100644 index 0000000..c794e0a --- /dev/null +++ b/windows/install-scoop.ps1 @@ -0,0 +1,2 @@ +Set-ExecutionPolicy RemoteSigned -Scope CurrentUser +irm get.scoop.sh | iex