maybe wezterm

master
Jordan Orelli 2 months ago
parent 0a7f70ba74
commit b2f4e57538

@ -3,3 +3,5 @@
email = jordanorelli@gmail.com
[pull]
rebase = true
[rebase]
instructionFormat = (%an <%ae>) %s

@ -45,6 +45,11 @@ when: host.has('kitty') and host.is_linux
files:
desktop/kitty.desktop > .local/share/applications/kitty.desktop
[home wezterm]
when: host.has('WezTerm.app')
files:
wezterm/config.lua > .wezterm.lua
[link-files nix-config]
when: host.has('nix')
target_root: ~/.config

@ -0,0 +1 @@
print("You are in lua")

@ -11,38 +11,40 @@ import pathlib
import shutil
from functools import cached_property
class Host:
"""
hacking the python module system a little to make the module look like a
singleton object so that it can have properties
"""
@cached_property
def is_wsl(self):
"""
true if we're running Linux on WSL
"""
return 'WSL2' in platform.platform()
return "WSL2" in platform.platform()
@cached_property
def is_linux(self):
"""
true if we're on linux (including WSL), false otherwise
"""
return platform.system() == 'Linux'
return platform.system() == "Linux"
@cached_property
def is_windows(self):
"""
true if we're on Windows (and running Python from Windows)
"""
return platform.system() == 'Windows'
return platform.system() == "Windows"
@cached_property
def is_darwin(self):
"""
true if we're on MacOS
"""
return platform.system() == 'Darwin'
return platform.system() == "Darwin"
@cached_property
def is_admin(self):
@ -69,10 +71,16 @@ class Host:
"""
return pathlib.Path.home()
def has(self, cmd):
def has(self, cmd: str):
"""
whether or not the machine has the specified command
"""
if self.is_darwin and cmd.endswith(".app"):
app_dir = pathlib.Path("/Applications")
app_path = app_dir / cmd
if app_path.exists():
return True
return shutil.which(cmd) is not None
sys.modules[__name__] = Host()

@ -1,27 +1,23 @@
import configparser
import json
import pathlib
import sys
from configparser import ConfigParser, SectionProxy
from functools import cached_property
from . import host
from . import sections
from . import targets
from .options import Options
from .resource import Resource
class Installer:
"""
manages the installation of preferences files
"""
def __init__(self):
self.options = Options.from_cli_args()
@cached_property
def config(self):
def config(self) -> ConfigParser:
path = self.options.config_path
with open(path, 'r', encoding='utf-8') as config_file:
parser = configparser.ConfigParser()
with open(path, "r", encoding="utf-8") as config_file:
parser = ConfigParser()
# make keys case-sensitive
parser.optionxform = str
parser.read_file(config_file)
@ -37,7 +33,14 @@ class Installer:
else:
print(f"SKIP [{name}]")
def when(self, section):
if clause := section.get('when', None):
return eval(clause)
def when(self, section: SectionProxy) -> bool:
if clause := section.get("when", None):
from . import host
given_locals = {
"host": host,
}
v = eval(clause, None, given_locals)
return bool(v)
return True

@ -4,10 +4,12 @@ import os
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
@ -23,8 +25,6 @@ class Linker:
parent_dir = target_path.parent
parent_dir.mkdir(parents=True)
exists = os.path.exists(str(target_path))
is_link = os.path.islink(str(target_path))
if target_path.exists():
if target_path.is_symlink():
if target_path.resolve() == source_path:
@ -38,7 +38,9 @@ class Linker:
print(f"rm {target_path} (dir)")
shutil.rmtree(target_path)
else:
print(f"skip {source_path}: unable to handle target at {target_path}: is not a symlink, file, or directory")
print(
f"skip {source_path}: unable to handle target at {target_path}: is not a symlink, file, or directory"
)
return
else:
if target_path.is_symlink():
@ -51,14 +53,15 @@ class Linker:
print(f"ERROR creating link: {e}")
print(f"link {target_path} -> {source_path}")
class LinkFiles:
resource_name = 'link-files'
resource_name = "link-files"
def __init__(self, label, section):
self.label = label
self.target_root = pathlib.Path(section['target_root']).expanduser()
self.target_root = pathlib.Path(section["target_root"]).expanduser()
self.source_root = host.dotfiles_root
self.parse_files(section.get('files', ''))
self.parse_files(section.get("files", ""))
def parse_files(self, text):
self.files = []
@ -73,8 +76,8 @@ class LinkFiles:
def __repr__(self):
if self.label:
return f'<LinkFiles: {self.label}>'
return '<LinkFiles>'
return f"<LinkFiles: {self.label}>"
return "<LinkFiles>"
def run(self):
linker = Linker(host.dotfiles_root, self.target_root)

@ -1,14 +1,22 @@
from configparser import SectionProxy
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, git.Repo]
resource_types: list[type] = [
Home,
LinkFiles,
CargoInstall,
Run,
git.Repo,
]
@classmethod
def from_name(cls, name):
def from_name(cls, name: str) -> type:
"""
from_name is to be implemented by resource classes
"""
@ -18,8 +26,8 @@ class Resource:
raise ValueError(f"No section type has name {name}")
@classmethod
def from_section(cls, name, section):
parts = name.split(' ')
def from_section(cls, name: str, section: SectionProxy):
parts = name.split(" ")
name = parts[0]
try:
label = parts[1]

@ -1,16 +1,15 @@
import subprocess
import os
import shutil
from . import host
class Run:
resource_name = '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)
self.cmd = section.get("cmd", "").split()
self.cwd = section.get("cwd", host.dotfiles_root)
self.shell = section.get("shell", False)
def run(self):
kwargs = {
@ -20,6 +19,7 @@ class Run:
"shell": self.shell,
}
with subprocess.Popen(self.cmd, **kwargs) as proc:
line = proc.stdout.read()
if line:
print(line)
if proc.stdout is not None:
line = proc.stdout.read()
if line:
print(line)

@ -0,0 +1,15 @@
from typing import Sequence, Tuple
from pathlib import Path
def parse_files(text: str) -> Sequence[Tuple[Path, Path]]:
files = []
lines = [s for s in text.splitlines() if s]
for line in lines:
parts = line.split(">", 2)
if len(parts) == 1:
pair = (Path(parts[0].strip()), Path(parts[0].strip()))
else:
pair = (Path(parts[0].strip()), Path(parts[1].strip()))
files.append(pair)
return files

@ -0,0 +1,47 @@
local wezterm = require 'wezterm'
local config = wezterm.config_builder()
-- JellyBeans is not recognized
-- config.color_scheme = 'JellyBeans'
config.adjust_window_size_when_changing_font_size = false
-- Set the default starting directory when opening the terminal
-- config.default_cwd
-- The scroll bar is disabled by default but sometimes when you have really
-- long output I like it.
config.enable_scroll_bar = true
-- whether or not the tab bar is shown
config.enable_tab_bar = true
-- hide the tab bar in windows that have only one tab
config.hide_tab_bar_if_only_one_tab = true
config.font_size = 14
config.launch_menu = {
{
args = { 'lazydocker' },
}
}
config.keys = {
{
key = 'Enter',
mods = 'CMD',
action = wezterm.action.ToggleFullScreen,
},
}
config.native_macos_fullscreen_mode = true
config.scrollback_lines = 10000
config.tab_bar_at_bottom = true
-- config.initial_cols = 90
-- config.initial_rows = 24
return config
Loading…
Cancel
Save