parent
30d476768f
commit
c6c489fc71
@ -1,7 +1,10 @@
|
|||||||
if !has('nvim')
|
" f5 runs the current project
|
||||||
nnoremap <buffer> <C-]> :ALEGoToDefinition<CR>
|
nmap <F5> :!clear<CR>:!cargo run -q<CR>
|
||||||
endif
|
nmap <S-F5> :!clear<CR>:!cargo run<CR>
|
||||||
|
|
||||||
nnoremap <F5> :Cargo run<CR>
|
" ctrl-f5 lets you run the current program but prompts you for the cli args
|
||||||
|
nmap <C-F5> :!clear<CR>:!cargo run --
|
||||||
|
|
||||||
let g:rustfmt_autosave = 1
|
nmap <F6> :!clear<CR>:!cargo run<CR>
|
||||||
|
nmap <F7> :!clear<CR>:!cargo check<CR>
|
||||||
|
nmap <F8> :!clear<CR>:!cargo test<CR>
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
"""
|
|
||||||
prefs is a preferences manager
|
|
||||||
"""
|
|
||||||
|
|
||||||
from .installer import Installer
|
|
@ -1,33 +1,32 @@
|
|||||||
class Home:
|
from . import host
|
||||||
def __init__(self, label = None):
|
from .linker import Linker
|
||||||
self.label = label
|
|
||||||
|
|
||||||
@classmethod
|
class Home:
|
||||||
def from_name(cls, name):
|
resource_name = 'home'
|
||||||
"""
|
|
||||||
Builds a Home struct from a given name
|
|
||||||
"""
|
|
||||||
if name.startswith('home'):
|
|
||||||
label = name.removeprefix('home').strip()
|
|
||||||
return cls(label)
|
|
||||||
return None
|
|
||||||
|
|
||||||
def parse_section(self, section):
|
def __init__(self, label, section):
|
||||||
mapping = {
|
self.label = label or None
|
||||||
'files': self.parse_files
|
self.parse_files(section.get('files', ''))
|
||||||
}
|
|
||||||
for key in section:
|
|
||||||
if fn := mapping.get(key):
|
|
||||||
val = section[key]
|
|
||||||
fn(val)
|
|
||||||
else:
|
|
||||||
raise KeyError(f"Home has no such config key: {key}")
|
|
||||||
|
|
||||||
def parse_files(self, text):
|
def parse_files(self, text):
|
||||||
|
self.files = []
|
||||||
lines = [s for s in text.splitlines() if s]
|
lines = [s for s in text.splitlines() if s]
|
||||||
print(f" parse_files: {lines}")
|
for line in lines:
|
||||||
|
parts = line.split(">", 2)
|
||||||
|
if len(parts) == 1:
|
||||||
|
pair = (parts[0].strip(), parts[0].strip())
|
||||||
|
else:
|
||||||
|
pair = (parts[0].strip(), parts[1].strip())
|
||||||
|
self.files.append(pair)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
if self.label:
|
if self.label:
|
||||||
return f'<Home: {self.label}>'
|
return f'<Home: {self.label}>'
|
||||||
return '<Home>'
|
return '<Home>'
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
linker = Linker(host.dotfiles_root, host.home)
|
||||||
|
for pair in self.files:
|
||||||
|
source_path = host.dotfiles_root / pair[0]
|
||||||
|
target_path = host.home / pair[1]
|
||||||
|
linker.link(source_path, target_path)
|
||||||
|
@ -0,0 +1,56 @@
|
|||||||
|
import pathlib
|
||||||
|
|
||||||
|
from . import host
|
||||||
|
|
||||||
|
class Linker:
|
||||||
|
"""
|
||||||
|
Linker links files from soome source to some target
|
||||||
|
"""
|
||||||
|
def __init__(self, source_root, target_root):
|
||||||
|
self.source_root = source_root
|
||||||
|
self.target_root = target_root
|
||||||
|
|
||||||
|
def link(self, source_path, target_path):
|
||||||
|
if not source_path.is_absolute():
|
||||||
|
source_path = self.source_root / source_path
|
||||||
|
if not target_path.is_absolute():
|
||||||
|
target_path = self.target_root / target_path
|
||||||
|
|
||||||
|
if not target_path.parent.exists():
|
||||||
|
print("creating missing parent directories for target")
|
||||||
|
parent_dir = target_path.parent
|
||||||
|
parent_dir.mkdir(parents=True)
|
||||||
|
|
||||||
|
print(f"{source_path} -> {target_path}")
|
||||||
|
|
||||||
|
class LinkFiles:
|
||||||
|
resource_name = 'link-files'
|
||||||
|
|
||||||
|
def __init__(self, label, section):
|
||||||
|
self.label = label
|
||||||
|
self.target_root = pathlib.Path(section['target_root']).expanduser()
|
||||||
|
self.source_root = host.dotfiles_root
|
||||||
|
self.parse_files(section.get('files', ''))
|
||||||
|
|
||||||
|
def parse_files(self, text):
|
||||||
|
self.files = []
|
||||||
|
lines = [s for s in text.splitlines() if s]
|
||||||
|
for line in lines:
|
||||||
|
parts = line.split(">", 2)
|
||||||
|
if len(parts) == 1:
|
||||||
|
pair = (parts[0].strip(), parts[0].strip())
|
||||||
|
else:
|
||||||
|
pair = (parts[0].strip(), parts[1].strip())
|
||||||
|
self.files.append(pair)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
if self.label:
|
||||||
|
return f'<LinkFiles: {self.label}>'
|
||||||
|
return '<LinkFiles>'
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
linker = Linker(host.dotfiles_root, self.target_root)
|
||||||
|
for pair in self.files:
|
||||||
|
source_path = pathlib.Path(pair[0])
|
||||||
|
target_path = pathlib.Path(pair[1])
|
||||||
|
linker.link(source_path, target_path)
|
Loading…
Reference in New Issue