1

Regenerate nvim config

This commit is contained in:
2024-06-02 03:29:20 +02:00
parent 75eea0c030
commit ef2e28883d
5576 changed files with 604886 additions and 503 deletions

View File

@ -0,0 +1,31 @@
from json import dump
from std2.graphlib import recur_sort
from std2.pickle.encoder import new_encoder
from chad_types import ARTIFACT, Artifact
from .icon_colours import load_icon_colours
from .ls_colours import load_ls_colours
from .text_decorations import load_text_decors
def main() -> None:
encode = new_encoder[Artifact](Artifact)
ls_colours = load_ls_colours()
icon_colours = load_icon_colours()
icons, text_colours = load_text_decors()
artifact = Artifact(
icons=icons,
ls_colours=ls_colours,
icon_colours=icon_colours,
text_colours=text_colours,
)
json = recur_sort(encode(artifact))
with ARTIFACT.open("w") as fd:
dump(json, fd, ensure_ascii=False, check_circular=False, indent=2)
main()

View File

@ -0,0 +1,47 @@
from dataclasses import dataclass
from typing import Mapping, Optional, Sequence
from std2.pickle.decoder import new_decoder
from std2.urllib import urlopen
from yaml import safe_load
from chad_types import Hex, IconColours, IconColourSet
_LINGUIST = """
https://raw.githubusercontent.com/github/linguist/master/lib/linguist/languages.yml
"""
@dataclass(frozen=True)
class _GithubColours:
extensions: Sequence[str] = ()
color: Optional[Hex] = None
_GithubSpec = Mapping[str, _GithubColours]
def _fetch(uri: str) -> str:
with urlopen(uri) as resp:
code = resp.getcode()
body = resp.read()
if code != 200:
raise Exception(resp.headers, body)
else:
return body.decode()
def load_icon_colours() -> IconColourSet:
decode = new_decoder[_GithubSpec](_GithubSpec, strict=False)
rawGH = _fetch(_LINGUIST)
yamlGH = decode(safe_load(rawGH))
github: IconColours = {
ext: spec.color
for spec in yamlGH.values()
for ext in spec.extensions
if spec.color
}
colours = IconColourSet(github=github)
return colours

View File

@ -0,0 +1,19 @@
FROM ubuntu:latest
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends -- python3 git ca-certificates && \
rm -rf -- /var/lib/apt/lists/* && \
update-ca-certificates
WORKDIR /root
RUN git clone --depth=1 https://github.com/seebi/dircolors-solarized.git && \
git clone --depth=1 https://github.com/arcticicestudio/nord-dircolors.git && \
git clone --depth=1 https://github.com/trapd00r/LS_COLORS
COPY . /
ENTRYPOINT ["./lsc.py"]

View File

@ -0,0 +1,18 @@
from json import loads
from pathlib import Path
from std2.pickle.decoder import new_decoder
from chad_types import LSColourSet
from ..run import docker_run
_DOCKERFILE = Path(__file__).resolve(strict=True).with_name("Dockerfile")
def load_ls_colours() -> LSColourSet:
decode = new_decoder[LSColourSet](LSColourSet)
json = loads(docker_run(_DOCKERFILE))
lsc = decode(json)
return lsc

View File

@ -0,0 +1,33 @@
#!/usr/bin/env python3
from json import dump
from os.path import normcase
from pathlib import Path
from subprocess import check_output
from sys import stdout
_LSC_SH = Path(__file__).resolve(strict=True).with_name("lsc.sh")
_SOLARIZED = Path("dircolors-solarized").resolve(strict=True)
_NORD = Path("nord-dircolors").resolve(strict=True)
_TRAP_DOOR = Path("LS_COLORS").resolve(strict=True)
_PARSING = {
_SOLARIZED / "dircolors.256dark": "solarized_dark_256",
_SOLARIZED / "dircolors.ansi-dark": "solarized_dark",
_SOLARIZED / "dircolors.ansi-light": "solarized_light",
_SOLARIZED / "dircolors.ansi-universal": "solarized_universal",
_NORD / "src" / "dir_colors": "nord",
_TRAP_DOOR / "LS_COLORS": "trapdoor",
}
def main() -> None:
lsc = {
dest: check_output((str(_LSC_SH), normcase(file_name)), text=True)
for file_name, dest in _PARSING.items()
}
dump(lsc, stdout, ensure_ascii=False, check_circular=False)
main()

View File

@ -0,0 +1,9 @@
#!/nix/store/306znyj77fv49kwnkpxmb0j2znqpa8bj-bash-5.2p26/bin/bash
set -eu
set -o pipefail
FILE="$1"
export TERM=xterm-256color
eval "$(dircolors -b "$FILE")"
printf '%s' "$LS_COLORS"

View File

@ -0,0 +1,82 @@
#!/usr/bin/env python3
from datetime import datetime, timezone
from os import environ, sep
from pathlib import Path
from subprocess import check_call, check_output, run
from sys import executable
from typing import Iterator
_TOP_LV = Path(__file__).resolve(strict=True).parent.parent
def _git_identity() -> None:
email = "ci@ci.ci"
username = "ci-bot"
check_call(("git", "config", "--global", "user.email", email))
check_call(("git", "config", "--global", "user.name", username))
def _get_branch() -> str:
if ref := environ.get("GITHUB_REF"):
return ref.replace("refs/heads/", "")
else:
br = check_output(("git", "branch", "--show-current"), text=True, cwd=_TOP_LV)
return br.strip()
def _git_clone(path: Path) -> None:
if not path.is_dir():
if token := environ.get("CI_TOKEN"):
uri = f"https://ms-jpq:{token}@github.com/ms-jpq/chadtree.git"
else:
uri = "git@github.com:ms-jpq/chadtree.git"
branch = _get_branch()
check_call(("git", "clone", "--branch", branch, uri, path))
def _build() -> None:
check_call((executable, "-m", "ci"), cwd=_TOP_LV)
def _git_alert(cwd: Path) -> None:
prefix = "ci"
remote_brs = check_output(("git", "branch", "--remotes"), text=True, cwd=cwd)
def cont() -> Iterator[str]:
for br in remote_brs.splitlines():
b = br.strip()
if b and "->" not in b:
_, _, name = b.partition(sep)
if name.startswith(prefix):
yield name
refs = tuple(cont())
if refs:
check_call(("git", "push", "--delete", "origin", *refs), cwd=cwd)
proc = run(("git", "diff", "--exit-code"), cwd=cwd)
print(proc)
if proc.returncode:
time = datetime.now(tz=timezone.utc).strftime("%Y-%m-%d")
brname = f"{prefix}--{time}"
check_call(("git", "checkout", "-b", brname), cwd=cwd)
check_call(("git", "add", "."), cwd=cwd)
check_call(("git", "commit", "-m", f"update_icons: {time}"), cwd=cwd)
check_call(
("git", "push", "--force", "--set-upstream", "origin", brname), cwd=cwd
)
def main() -> None:
cwd = Path() / "temp"
if "CI" in environ:
_git_identity()
_git_clone(cwd)
_build()
_git_alert(_TOP_LV)
main()

View File

@ -0,0 +1,25 @@
from pathlib import Path
from subprocess import check_call, check_output
def docker_run(dockerfile: Path) -> str:
parent = dockerfile.parent
name = f"chad_{parent.name}"
check_call(
(
"docker",
"buildx",
"build",
"--progress",
"plain",
"--tag",
name,
"--file",
dockerfile,
"--",
".",
),
cwd=parent,
)
output = check_output(("docker", "run", "--rm", name), text=True)
return output

View File

@ -0,0 +1,21 @@
FROM ubuntu:latest
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends -- neovim git ca-certificates && \
rm -rf -- /var/lib/apt/lists/*
WORKDIR /root
RUN git clone --depth=1 https://github.com/ryanoasis/vim-devicons.git && \
git clone --depth=1 https://github.com/adelarsq/vim-emoji-icon-theme.git && \
git clone --depth=1 https://github.com/tiagofumo/vim-nerdtree-syntax-highlight.git
COPY . /
RUN nvim --headless
ENTRYPOINT ["cat", "exports.json"]

View File

@ -0,0 +1,104 @@
from dataclasses import dataclass
from json import loads
from pathlib import Path
from typing import Mapping, Tuple
from std2.coloursys import hex_inverse
from std2.graphlib import merge
from std2.pickle.decoder import new_decoder
from yaml import safe_load
from chad_types import ASSETS, Hex, IconGlyphs, IconGlyphSet, TextColours, TextColourSet
from ..run import docker_run
@dataclass(frozen=True)
class _TCAliases:
ext_exact: Mapping[str, str]
name_exact: Mapping[str, str]
name_glob: Mapping[str, str]
@dataclass(frozen=True)
class _Aliases:
icon_colours: Mapping[str, str]
text_colours: _TCAliases
_DOCKERFILE = Path(__file__).resolve(strict=True).with_name("Dockerfile")
_ICON_BASE = ASSETS / "icon_base.yml"
_ALIASES = ASSETS / "aliases.yml"
def _process_exts(exts: Mapping[str, str]) -> Mapping[str, str]:
return {f".{k}": v for k, v in exts.items()}
def _process_glob(glob: Mapping[str, str]) -> Mapping[str, str]:
return {k.rstrip("$").replace(r"\.", "."): v for k, v in glob.items()}
def _process_hexcode(colours: Mapping[str, str]) -> Mapping[str, Hex]:
return {k: f"#{v}" for k, v in colours.items()}
def _process_inverse(colours: Mapping[str, str]) -> Mapping[str, str]:
return {k: hex_inverse(v) for k, v in colours.items()}
def _process_icons(icons: IconGlyphs) -> IconGlyphs:
return IconGlyphs(
default_icon=icons.default_icon,
folder=icons.folder,
link=icons.link,
status=icons.status,
ext_exact=_process_exts(icons.ext_exact),
name_exact=icons.name_exact,
name_glob=_process_glob(icons.name_glob),
)
def _process_colours(colours: TextColours) -> TextColours:
return TextColours(
ext_exact=_process_hexcode(_process_exts(colours.ext_exact)),
name_exact=_process_hexcode(colours.name_exact),
name_glob=_process_hexcode(_process_glob(colours.name_glob)),
)
def _make_lightmode(colours: TextColours) -> TextColours:
return TextColours(
ext_exact=_process_inverse(colours.ext_exact),
name_exact=_process_inverse(colours.name_exact),
name_glob=_process_inverse(colours.name_glob),
)
def load_text_decors() -> Tuple[IconGlyphSet, TextColourSet]:
i_decode = new_decoder[IconGlyphSet](IconGlyphSet, strict=False)
c_decode = new_decoder[TextColourSet](TextColourSet, strict=False)
a_decode = new_decoder[_Aliases](_Aliases)
icon_base = safe_load(_ICON_BASE.read_text("UTF-8"))
aliases = safe_load(_ALIASES.read_text("UTF-8"))
json = loads(docker_run(_DOCKERFILE))
data = merge(json, icon_base)
icon_spec = i_decode(data)
ali = a_decode(aliases)
icon_set = IconGlyphSet(
ascii=_process_icons(icon_spec.ascii),
ascii_hollow=_process_icons(icon_spec.ascii_hollow),
devicons=_process_icons(icon_spec.devicons),
emoji=_process_icons(icon_spec.emoji),
)
colour_spec = c_decode(data)
colour_set = TextColourSet(
nerdtree_syntax_light=_make_lightmode(
_process_colours(colour_spec.nerdtree_syntax_light)
),
nerdtree_syntax_dark=_process_colours(colour_spec.nerdtree_syntax_dark),
)
return icon_set, colour_set

View File

@ -0,0 +1 @@
lua require 'chad'

View File

@ -0,0 +1,49 @@
local export_icons = function()
return {
ext_exact = vim.g.WebDevIconsUnicodeDecorateFileNodesExtensionSymbols,
name_exact = vim.g.WebDevIconsUnicodeDecorateFileNodesExactSymbols,
name_glob = vim.g.WebDevIconsUnicodeDecorateFileNodesPatternSymbols,
default_icon = vim.g.WebDevIconsUnicodeDecorateFileNodesDefaultSymbol,
folder = {
open = vim.g.DevIconsDefaultFolderOpenSymbol,
closed = vim.g.WebDevIconsUnicodeDecorateFolderNodesDefaultSymbol
}
}
end
local export_colours = function()
return {
ext_exact = vim.g.NERDTreeExtensionHighlightColor,
name_exact = vim.g.NERDTreeExactMatchHighlightColor,
name_glob = vim.g.NERDTreePatternMatchHighlightColor
}
end
local load_rtp = function(src)
vim.o.runtimepath = vim.o.runtimepath .. "," .. "/root/" .. src
end
local load_viml = function(src)
vim.cmd("source " .. "/root/" .. src)
end
load_viml "vim-devicons/plugin/webdevicons.vim"
local devicons = export_icons()
load_viml "vim-emoji-icon-theme/plugin/vim-emoji-icon-theme.vim"
local emoji = export_icons()
load_viml "vim-nerdtree-syntax-highlight/after/syntax/nerdtree.vim"
local nerdtree_syntax = export_colours()
local exports = {
devicons = devicons,
emoji = emoji,
nerdtree_syntax_light = nerdtree_syntax,
nerdtree_syntax_dark = nerdtree_syntax
}
local json = vim.fn.json_encode(exports)
vim.fn.writefile({json}, "exports.json")
os.exit(0)