7d0ceb4e1c
- dev: 异常捕获改为 except Exception 适配 decman 自定义异常 - docker/zsh/wsl: on_enable 改为 after_update + 状态检查确保收敛 - docker/zsh: subprocess 失败时 early return 避免误触发 - wsl: systemctl 调用加 try/except 防止 systemd 不可用时崩溃 - zsh: shell 路径改为精确解析 passwd 字段 - docker: decorator 别名统一为 pacman_packages - install.sh: 开头验证 sudo 权限、mkdir -p 确保父目录、[ 改 [[ - wsl-init.sh: pacman -Sy 改 -Syu 避免 partial upgrade、已有用户补 wheel 组
53 lines
1.4 KiB
Python
53 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):
|
|
return {
|
|
f"/home/{self.user}/.zshenv": File(
|
|
source_file="./home/.zshenv",
|
|
owner=self.user,
|
|
),
|
|
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",
|
|
"oh-my-zsh-git",
|
|
}
|
|
|
|
def after_update(self, store):
|
|
result = subprocess.run(
|
|
["getent", "passwd", self.user], capture_output=True, text=True
|
|
)
|
|
if result.returncode != 0:
|
|
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])
|