AutoYADM commit: 2025-04-22 17:30:06
This commit is contained in:
parent
43787f46f3
commit
b73faec60c
1 changed files with 25 additions and 13 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue