mirror of
https://github.com/js0ny/dotfiles.git
synced 2026-03-22 02:36:19 +00:00
sioyek: add sioyek script
Some checks failed
Shell Script Check & Format / shell-check (push) Has been cancelled
Some checks failed
Shell Script Check & Format / shell-check (push) Has been cancelled
This commit is contained in:
parent
78cff324ed
commit
2b403b18e4
6 changed files with 105 additions and 11 deletions
|
|
@ -26,7 +26,7 @@
|
||||||
../../modules/nixos/desktop/xremap.nix
|
../../modules/nixos/desktop/xremap.nix
|
||||||
|
|
||||||
# desktop environment and display manager
|
# desktop environment and display manager
|
||||||
../../modules/nixos/desktop/dm/sddm.nix
|
../../modules/nixos/desktop/dm/gdm.nix
|
||||||
../../modules/nixos/desktop/de/niri.nix
|
../../modules/nixos/desktop/de/niri.nix
|
||||||
../../modules/nixos/desktop/de/gnome.nix
|
../../modules/nixos/desktop/de/gnome.nix
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,5 +67,6 @@ in {
|
||||||
in {
|
in {
|
||||||
"/usr/share/icons" = mkRoSymBind "${aggregated}/share/icons";
|
"/usr/share/icons" = mkRoSymBind "${aggregated}/share/icons";
|
||||||
"/usr/share/fonts" = mkRoSymBind "${aggregated}/share/fonts";
|
"/usr/share/fonts" = mkRoSymBind "${aggregated}/share/fonts";
|
||||||
|
"/home/js0ny/.local/share/fonts" = mkRoSymBind "${aggregated}/share/fonts";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,33 @@
|
||||||
{...}: {
|
{
|
||||||
|
pkgs,
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
sioyekCopyScript = pkgs.writeShellApplication {
|
||||||
|
name = "sioyek-copy-page";
|
||||||
|
runtimeInputs = with pkgs;
|
||||||
|
[poppler-utils]
|
||||||
|
++ (
|
||||||
|
if pkgs.stdenv.isLinux
|
||||||
|
then with pkgs; [wl-clipboard libnotify]
|
||||||
|
else []
|
||||||
|
);
|
||||||
|
text = builtins.readFile ./sioyek-copy-page.sh;
|
||||||
|
};
|
||||||
|
in {
|
||||||
|
xdg.configFile."sioyek/prefs_user.config".text = ''
|
||||||
|
new_command _copy_page_to_clipboard ${lib.getExe sioyekCopyScript} %{page_number} %{file_path}
|
||||||
|
default_dark_mode 1
|
||||||
|
font_size 14
|
||||||
|
case_sensitive_search 0
|
||||||
|
super_fast_search 1
|
||||||
|
search_url_d https://duckduckgo.com/?q=
|
||||||
|
search_url_e https://ai.js0ny.net/?models=qwen%2Fqwen3-235b-a22b-2507&q=explain-
|
||||||
|
'';
|
||||||
programs.sioyek = {
|
programs.sioyek = {
|
||||||
enable = true;
|
enable = true;
|
||||||
# prefs_user.config
|
# prefs_user.config
|
||||||
config = {
|
|
||||||
default_dark_mode = "1";
|
|
||||||
font_size = "14";
|
|
||||||
case_sensitive_search = "0";
|
|
||||||
super_fast_search = "1";
|
|
||||||
search_url_d = "https://duckduckgo.com/?q=";
|
|
||||||
};
|
|
||||||
bindings = {
|
bindings = {
|
||||||
## Movement
|
## Movement
|
||||||
"screen_down" = "J";
|
"screen_down" = "J";
|
||||||
|
|
@ -51,6 +70,9 @@
|
||||||
|
|
||||||
"command" = "<A-x>";
|
"command" = "<A-x>";
|
||||||
"search" = "<C-f>";
|
"search" = "<C-f>";
|
||||||
|
|
||||||
|
## User Defined Commands
|
||||||
|
"_copy_page_to_clipboard" = "<A-c>";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
71
nixcfgs/users/js0ny/programs/sioyek/sioyek-copy-page.sh
Normal file
71
nixcfgs/users/js0ny/programs/sioyek/sioyek-copy-page.sh
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
RAW_PAGE="$1"
|
||||||
|
RAW_PATH="$2"
|
||||||
|
FILE_PATH="$RAW_PATH"
|
||||||
|
|
||||||
|
# FILE_PATH="${RAW_PATH#\"}" # 去除开头的 "
|
||||||
|
# FILE_PATH="${FILE_PATH%\"}" # 去除结尾的 "
|
||||||
|
# FILE_PATH="${FILE_PATH#\'}" # 去除开头的 '
|
||||||
|
# FILE_PATH="${FILE_PATH%\'}" # 去除结尾的 '
|
||||||
|
|
||||||
|
PAGE_NUM="$RAW_PAGE"
|
||||||
|
DISPLAY_PAGE=$((PAGE_NUM + 1))
|
||||||
|
DPI=300
|
||||||
|
|
||||||
|
notify() {
|
||||||
|
local msg="$1"
|
||||||
|
local level="${2:-normal}" # normal / critical
|
||||||
|
|
||||||
|
if [[ "$(uname)" == "Darwin" ]]; then
|
||||||
|
osascript -e "display notification \"$msg\" with title \"Sioyek\""
|
||||||
|
elif command -v notify-send >/dev/null 2>&1; then
|
||||||
|
notify-send -u "$level" -a "Sioyek" "Page Copy" "$msg"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
if ! command -v pdftocairo >/dev/null 2>&1; then
|
||||||
|
notify "缺少依赖: pdftocairo (请安装 poppler_utils)" "critical"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! -f "$FILE_PATH" ]]; then
|
||||||
|
notify "文件不存在: $FILE_PATH" "critical"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
OS_TYPE=$(uname)
|
||||||
|
|
||||||
|
if [[ "$OS_TYPE" == "Darwin" ]]; then
|
||||||
|
TMP_IMG=$(mktemp /tmp/sioyek_page.XXXXXX.png)
|
||||||
|
|
||||||
|
# 渲染到临时文件
|
||||||
|
pdftocairo -png -f "$PAGE_NUM" -l "$PAGE_NUM" -r "$DPI" -singlefile "$FILE_PATH" "${TMP_IMG%.png}"
|
||||||
|
|
||||||
|
if [[ -f "$TMP_IMG" ]]; then
|
||||||
|
# 写入剪贴板
|
||||||
|
osascript -e "set the clipboard to (read (POSIX file \"$TMP_IMG\") as JPEG picture)"
|
||||||
|
rm "$TMP_IMG"
|
||||||
|
notify "已复制第 $DISPLAY_PAGE 页"
|
||||||
|
else
|
||||||
|
notify "渲染失败" "critical"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
elif [[ "$OS_TYPE" == "Linux" ]]; then
|
||||||
|
if ! command -v wl-copy >/dev/null 2>&1; then
|
||||||
|
notify "缺少依赖: wl-copy (请安装 wl-clipboard)" "critical"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 使用管道直接传输,set -o pipefail 确保渲染失败时报错
|
||||||
|
set -o pipefail
|
||||||
|
if pdftocairo -png -f "$PAGE_NUM" -l "$PAGE_NUM" -r "$DPI" -singlefile "$FILE_PATH" - | wl-copy --type image/png; then
|
||||||
|
sleep 0.1
|
||||||
|
notify "已复制第 $DISPLAY_PAGE 页"
|
||||||
|
else
|
||||||
|
notify "复制失败 (pdftocairo 或 wl-copy 出错)" "critical"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
./programs/tmux.nix
|
./programs/tmux.nix
|
||||||
./programs/kitty.nix
|
./programs/kitty.nix
|
||||||
./programs/anki.nix
|
./programs/anki.nix
|
||||||
./programs/sioyek.nix
|
./programs/sioyek
|
||||||
./programs/telegram.nix
|
./programs/telegram.nix
|
||||||
# ./programs/retroarch.nix # Package broken on macOS
|
# ./programs/retroarch.nix # Package broken on macOS
|
||||||
./programs/darwin/duti.nix
|
./programs/darwin/duti.nix
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ in {
|
||||||
./programs/block-desktop-entries.nix
|
./programs/block-desktop-entries.nix
|
||||||
./programs/pwa.nix
|
./programs/pwa.nix
|
||||||
./programs/walker.nix
|
./programs/walker.nix
|
||||||
./programs/sioyek.nix
|
./programs/sioyek
|
||||||
./programs/celluloid.nix
|
./programs/celluloid.nix
|
||||||
./programs/picard.nix
|
./programs/picard.nix
|
||||||
./programs/cider-2.nix
|
./programs/cider-2.nix
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue