rofi modes and sdcv ECDICT

This commit is contained in:
js0ny 2025-11-21 15:31:34 +00:00
parent 56ec13855a
commit 57bee38531
2 changed files with 78 additions and 6 deletions

View file

@ -7,6 +7,31 @@
catppuccinEnable = config.catppuccin.enable or false;
catppuccinFlavor = config.catppuccin.flavor or "mocha";
catppuccinAccent = config.catppuccin.accent or "mauve";
# https://github.com/sentriz/cliphist/blob/master/contrib/cliphist-rofi-img
cliphistRofiImg = pkgs.writeShellScriptBin "cliphist-rofi-img" ''
#!/usr/bin/env bash
tmp_dir="/tmp/cliphist"
rm -rf "$tmp_dir"
if [[ -n "$1" ]]; then
cliphist decode <<<"$1" | wl-copy
exit
fi
mkdir -p "$tmp_dir"
read -r -d "" prog <<EOF
/^[0-9]+\s<meta http-equiv=/ { next }
match(\$0, /^([0-9]+)\s(\[\[\s)?binary.*(jpg|jpeg|png|bmp)/, grp) {
system("echo " grp[1] "\\\\\t | cliphist decode >$tmp_dir/"grp[1]"."grp[3])
print \$0"\0icon\x1f$tmp_dir/"grp[1]"."grp[3]
next
}
1
EOF
cliphist list | gawk "$prog"
'';
in {
programs.rofi = {
enable = true;
@ -15,6 +40,28 @@ in {
rofimoji
rofi-power-menu
rofi-calc
rofi-obsidian
cliphistRofiImg
];
modes = [
"run"
"ssh"
{
name = "clipboard";
path = lib.getExe cliphistRofiImg;
}
"drun"
"window"
"combi"
"calc"
# {
# name = "obsidian";
# path = lib.getExe pkgs.rofi-obsidian;
# }
{
name = "emoji";
path = lib.getExe pkgs.rofimoji;
}
];
};

View file

@ -1,15 +1,20 @@
{pkgs, ...}: let
dictBz2 = [
dictSources = [
{
# 朗道英汉字典
# 朗道英汉字典
url = "http://download.huzheng.org/zh_CN/stardict-langdao-ec-gb-2.4.2.tar.bz2";
sha256 = "68adfd6348418725b1810b5aeda2506ce44ddbc1ad99f2f68f6ba135cd3bf03c";
}
{
# 朗道汉英字典
# 朗道汉英字典
url = "http://download.huzheng.org/zh_CN/stardict-langdao-ce-gb-2.4.2.tar.bz2";
sha256 = "d539239f4920aa308582fba53918ea16844b6a2378cb74f9b99bfaec6e2f4f30";
}
{
# ECDICT (The Ultimate Dictionary)
url = "https://github.com/skywind3000/ECDICT/releases/download/1.0.28/ecdict-stardict-28.zip";
sha256 = "sha256-xwfQ897W7Hm5ZGbaShV04HRwPaWvnBIPutl/nLCMbyw=";
}
];
fetchedArchives = map (spec:
@ -17,26 +22,46 @@
url = spec.url;
sha256 = spec.sha256;
})
dictBz2;
dictSources;
stardict-dicts = pkgs.stdenv.mkDerivation {
name = "stardict-dictionaries-combined";
srcs = fetchedArchives;
sourceRoot = ".";
# 需要 unzip 来解压 zip 文件
nativeBuildInputs = [pkgs.unzip];
installPhase = ''
mkdir -p $out
for src in $srcs; do
tar -xjvf $src -C $out --strip-components=1
if [[ "$src" == *.zip ]]; then
# zip 文件直接解压到输出目录 (保留原有文件夹结构)
unzip $src -d $out
else
# tar.bz2 文件解压并剥离第一层目录 (兼容旧逻辑)
tar -xjvf $src -C $out --strip-components=1
fi
done
'';
};
# See: https://github.com/Dushistov/sdcv/issues/107
fzfSdcv = pkgs.writeShellScriptBin "sdcv-fzf" ''
fzf --prompt="Dict: " \
--phony \
--bind "enter:reload(sdcv {q} -n --json | jq '.[].dict' -r)" \
--preview "sdcv {q} -en --use-dict={}" \
--preview-window=wrap \
< <(echo)
'';
in {
home.packages = with pkgs; [
sdcv
fzfSdcv
];
home.file.".local/share/stardict/dic" = {
xdg.dataFile."stardict/dic" = {
source = stardict-dicts;
};
}