b96e144e82
- 全模块补全类型注解 (files, after_update, on_change) - docker: 仅在 WSL 环境禁用 networkd-wait-online - docker: 添加 _is_wsl() 自动检测函数 - zsh/docker: 改进错误输出使用 decman.error - wsl-init: 统一使用 [[ ]] 并格式化代码
52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
import subprocess
|
|
|
|
import decman
|
|
from decman import File, Module
|
|
from decman.plugins.aur import packages as aur_packages
|
|
from decman.plugins.pacman import packages as pacman_packages
|
|
|
|
|
|
class ZshModule(Module):
|
|
def __init__(self, user: str):
|
|
super().__init__("zsh")
|
|
self.user = user
|
|
|
|
def files(self) -> dict[str, File]:
|
|
return {
|
|
f"/home/{self.user}/.zshrc": File(
|
|
source_file="./home/.zshrc",
|
|
owner=self.user,
|
|
),
|
|
}
|
|
|
|
@pacman_packages
|
|
def pacman_packages(self) -> set[str]:
|
|
return {
|
|
"fzf",
|
|
"zsh",
|
|
"zsh-autosuggestions",
|
|
"zsh-completions",
|
|
"zsh-syntax-highlighting",
|
|
}
|
|
|
|
@aur_packages
|
|
def aur_packages(self) -> set[str]:
|
|
return {
|
|
"fzf-tab-git",
|
|
}
|
|
|
|
def after_update(self, store: object) -> None:
|
|
result = subprocess.run(
|
|
["getent", "passwd", self.user],
|
|
capture_output=True,
|
|
text=True,
|
|
check=False,
|
|
)
|
|
if result.returncode != 0:
|
|
decman.error(f"无法读取用户 {self.user} 的 passwd 信息")
|
|
return
|
|
# passwd 格式: name:x:uid:gid:gecos:home:shell
|
|
shell = result.stdout.strip().split(":")[-1]
|
|
if shell != "/usr/bin/zsh":
|
|
decman.prg(["chsh", "-s", "/usr/bin/zsh", self.user])
|