From 31527457bef5f5639769ae41926cc0b908d89be3 Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Tue, 22 Apr 2025 17:45:06 -0400 Subject: [PATCH] AutoYADM commit: 2025-04-22 17:45:06 --- .config/helix/config.toml | 2 +- .config/helix/scripts/typst-zathura.fish | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/.config/helix/config.toml b/.config/helix/config.toml index 1372fab1..660e0c85 100644 --- a/.config/helix/config.toml +++ b/.config/helix/config.toml @@ -183,7 +183,7 @@ C-u = ["page_cursor_half_up", "align_view_center"] # typst [keys.normal.space.l.t] # open pdf preview -p = ':sh ~/.config/helix/scripts/typst-zathura.fish %{buffer_name}' +p = ':sh ~/.config/helix/scripts/typst-zathura.fish -k %{buffer_name}' # git stuff [keys.normal.space.g] diff --git a/.config/helix/scripts/typst-zathura.fish b/.config/helix/scripts/typst-zathura.fish index dc4f5ed0..6f3f1c10 100755 --- a/.config/helix/scripts/typst-zathura.fish +++ b/.config/helix/scripts/typst-zathura.fish @@ -1,7 +1,7 @@ #!/usr/bin/env fish argparse q/quiet k/kill-on-exit h/help -- $argv -if test (count $argv) -e 0; or set -q _flag_h +if test (count $argv) -eq 0; or set -q _flag_h echo "Helper script for opening Typst files from Helix in Zathura." echo "Usage: (bind the following to a key)" echo ':sh typst-zathura [opts] %{buffer_name}' @@ -44,22 +44,23 @@ function find_parent_process -a target return 1 end -set -q _flag_k; and set parent_pid (find_parent_process hx) -if set -q _flag_k; and test -z "$parent_pid" - qecho "Couldn't find parent hx process!" - return $ret +if set -q _flag_k + set kill_parent + echo "kill flag set" + set parent_pid (find_parent_process hx) + if test -z "$parent_pid" + qecho "Couldn't find parent hx process!" + return $ret + end end # opens zathura, watching for helix closing function zopen --wraps zathura - if set -q _flag_k + if set -q kill_parent begin zathura "$argv[1]" &>/dev/null & set zathura_pid $last_pid - notify-send zathura "$zathura_pid" - notify-send hx $parent_pid waitpid "$parent_pid" - notify-send "helix killed" kill $zathura_pid end & else @@ -71,7 +72,7 @@ function find_pdf set -l root $argv[1] set -l base $argv[2] set -l candidate (fd --no-ignore-vcs -F -1 "$base" "$root") - if test "$candidate" != '' + if test -n "$candidate" zopen "$candidate" else return 1 @@ -85,6 +86,7 @@ if not string match -q '*.typ' $src end set -l targ (string replace '.typ' '.pdf' $src) set -l base (path basename --no-extension $src).pdf + if test -f "$targ" -a '' != '' # zathura "$targ" &>/dev/null & zopen "$targ" @@ -104,7 +106,7 @@ else if set -q _flag_q return 1 else - echo "$base couldn't be found!" + echo "$base couldn't be found at root $root!" end end end