AutoYADM commit: 2025-04-22 17:30:06

This commit is contained in:
Daniel Fichtinger 2025-04-22 17:30:06 -04:00
parent 43787f46f3
commit b73faec60c

View file

@ -1,5 +1,15 @@
#!/usr/bin/env fish #!/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 # only return status 1 if -q not set
if set -q _flag_q if set -q _flag_q
@ -34,23 +44,27 @@ function find_parent_process -a target
return 1 return 1
end end
set parent_pid (find_parent_process hx) set -q _flag_k; and set parent_pid (find_parent_process hx)
if test -z "$parent_pid" if set -q _flag_k; and test -z "$parent_pid"
qecho "Couldn't find parent hx process!" qecho "Couldn't find parent hx process!"
return $ret return $ret
end end
# opens zathura, watching for helix closing # opens zathura, watching for helix closing
function zopen --wraps zathura function zopen --wraps zathura
if set -q _flag_k
begin begin
zathura "$argv[1]" &>/dev/null & zathura "$argv[1]" &>/dev/null &
set zathura_pid $last_pid set zathura_pid $last_pid
notify-send zathura "$zathura_pid" notify-send zathura "$zathura_pid"
notify-send hx $parent_pid notify-send hx $parent_pid
inotifywait -e delete_self /proc/$parent_pid waitpid "$parent_pid"
notify-send "helix killed" notify-send "helix killed"
kill $zathura_pid kill $zathura_pid
end & end &
else
zathura "$argv[1]" &>/dev/null &
end
end end
function find_pdf function find_pdf
@ -65,8 +79,6 @@ function find_pdf
end end
set -l src (path resolve $argv[1]) set -l src (path resolve $argv[1])
# echo $src
# string replace
if not string match -q '*.typ' $src if not string match -q '*.typ' $src
qecho "$(path basename $src) is not a Typst file!" qecho "$(path basename $src) is not a Typst file!"
return $ret return $ret