From b73faec60c7530a6ef8bd9107b7e05cc0d69f2e7 Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Tue, 22 Apr 2025 17:30:06 -0400 Subject: [PATCH] AutoYADM commit: 2025-04-22 17:30:06 --- .config/helix/scripts/typst-zathura.fish | 38 ++++++++++++++++-------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/.config/helix/scripts/typst-zathura.fish b/.config/helix/scripts/typst-zathura.fish index b3df94fc..dc4f5ed0 100755 --- a/.config/helix/scripts/typst-zathura.fish +++ b/.config/helix/scripts/typst-zathura.fish @@ -1,5 +1,15 @@ #!/usr/bin/env fish -argparse q/quiet -- $argv +argparse q/quiet k/kill-on-exit h/help -- $argv + +if test (count $argv) -e 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}' + echo "Options:" + echo "-q/--quiet: Don't `echo` on caught errors, return 1 instead." + echo "-k/--kill-on-exit: Kill Zathura when parent Helix exits." + echo "-h/--help: print this screen" +end # only return status 1 if -q not set if set -q _flag_q @@ -34,23 +44,27 @@ function find_parent_process -a target return 1 end -set parent_pid (find_parent_process hx) -if test -z "$parent_pid" +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 end # opens zathura, watching for helix closing function zopen --wraps zathura - begin + if set -q _flag_k + 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 zathura "$argv[1]" &>/dev/null & - set zathura_pid $last_pid - notify-send zathura "$zathura_pid" - notify-send hx $parent_pid - inotifywait -e delete_self /proc/$parent_pid - notify-send "helix killed" - kill $zathura_pid - end & + end end function find_pdf @@ -65,8 +79,6 @@ function find_pdf end set -l src (path resolve $argv[1]) -# echo $src -# string replace if not string match -q '*.typ' $src qecho "$(path basename $src) is not a Typst file!" return $ret