45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
import subprocess
|
|
|
|
import decman
|
|
from decman import File, Module
|
|
from decman.plugins.pacman import packages as pacman_packages
|
|
|
|
|
|
class FishModule(Module):
|
|
def __init__(self, user: str):
|
|
super().__init__("fish")
|
|
self.user = user
|
|
|
|
def files(self) -> dict[str, File]:
|
|
return {
|
|
f"/home/{self.user}/.config/fish/config.fish": File(
|
|
source_file="./home/.config/fish/config.fish",
|
|
owner=self.user,
|
|
),
|
|
f"/home/{self.user}/.config/fish/functions/yy.fish": File(
|
|
source_file="./home/.config/fish/functions/yy.fish",
|
|
owner=self.user,
|
|
),
|
|
}
|
|
|
|
@pacman_packages
|
|
def pacman_packages(self) -> set[str]:
|
|
return {
|
|
"fish",
|
|
"fzf",
|
|
}
|
|
|
|
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:
|
|
raise decman.SourceError(f"无法读取用户 {self.user} 的 passwd 信息")
|
|
# passwd 格式: name:x:uid:gid:gecos:home:shell
|
|
shell = result.stdout.strip().split(":")[-1]
|
|
if shell != "/usr/bin/fish":
|
|
decman.prg(["chsh", "-s", "/usr/bin/fish", self.user])
|