AutoYADM commit: 2025-04-23 18:45:05
This commit is contained in:
parent
068b1da3c2
commit
8fb20348d6
1 changed files with 127 additions and 131 deletions
|
@ -9,10 +9,9 @@
|
||||||
# Author: Daniel Fichtinger <daniel@ficd.ca
|
# Author: Daniel Fichtinger <daniel@ficd.ca
|
||||||
# License: MIT
|
# License: MIT
|
||||||
|
|
||||||
function hx-typ-zathura
|
argparse q/quiet k/kill-on-exit h/help -- $argv
|
||||||
argparse q/quiet k/kill-on-exit h/help -- $argv
|
|
||||||
|
|
||||||
if test (count $argv) -eq 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."\n
|
echo "Helper script for opening Typst files from Helix in Zathura."\n
|
||||||
echo "Usage: (bind the following to a key)"
|
echo "Usage: (bind the following to a key)"
|
||||||
echo ':sh hx-typ-zathura.fish [opts] %{buffer_name}'\n
|
echo ':sh hx-typ-zathura.fish [opts] %{buffer_name}'\n
|
||||||
|
@ -26,26 +25,26 @@ function hx-typ-zathura
|
||||||
echo 'Author: Daniel Fichtinger <daniel@ficd.ca>'
|
echo 'Author: Daniel Fichtinger <daniel@ficd.ca>'
|
||||||
echo 'License: MIT'
|
echo 'License: MIT'
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
# only return status 1 if -q not set
|
# only return status 1 if -q not set
|
||||||
# (if return status != 0, helix will not
|
# (if return status != 0, helix will not
|
||||||
# display anything that was echoed to stdout!)
|
# display anything that was echoed to stdout!)
|
||||||
if set -q _flag_q
|
if set -q _flag_q
|
||||||
set ret 1
|
set ret 1
|
||||||
else
|
else
|
||||||
set ret 0
|
set ret 0
|
||||||
end
|
end
|
||||||
|
|
||||||
# only echo if -q not set
|
# only echo if -q not set
|
||||||
function qecho
|
function qecho
|
||||||
if test "$ret" -ne 1
|
if test "$ret" -ne 1
|
||||||
echo $argv[1]
|
echo $argv[1]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# check if the user asked to kill zathura on helix exit
|
# check if the user asked to kill zathura on helix exit
|
||||||
if set -q _flag_k
|
if set -q _flag_k
|
||||||
set kill_parent
|
set kill_parent
|
||||||
# traverse up process tree to find caller Helix PID
|
# traverse up process tree to find caller Helix PID
|
||||||
# We use this PID to kill zathura if Helix exits first!
|
# We use this PID to kill zathura if Helix exits first!
|
||||||
|
@ -78,10 +77,10 @@ function hx-typ-zathura
|
||||||
qecho "Couldn't find parent hx process!"
|
qecho "Couldn't find parent hx process!"
|
||||||
return $ret
|
return $ret
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# opens zathura, optionally watching for helix closing
|
# opens zathura, optionally watching for helix closing
|
||||||
function zopen --wraps zathura
|
function zopen --wraps zathura
|
||||||
# this should be set if the user asked to watch
|
# this should be set if the user asked to watch
|
||||||
if set -q kill_parent
|
if set -q kill_parent
|
||||||
# create background sub-process
|
# create background sub-process
|
||||||
|
@ -97,10 +96,10 @@ function hx-typ-zathura
|
||||||
zathura "$argv[1]" &>/dev/null &
|
zathura "$argv[1]" &>/dev/null &
|
||||||
end
|
end
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
# try to find the target pdf file searching from root
|
# try to find the target pdf file searching from root
|
||||||
function find_pdf
|
function find_pdf
|
||||||
set -l root $argv[1]
|
set -l root $argv[1]
|
||||||
set -l base $argv[2]
|
set -l base $argv[2]
|
||||||
set -l candidate (fd --no-ignore-vcs -F -1 "$base" "$root")
|
set -l candidate (fd --no-ignore-vcs -F -1 "$base" "$root")
|
||||||
|
@ -109,24 +108,24 @@ function hx-typ-zathura
|
||||||
else
|
else
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# absolute path of %{buffer_name} file
|
# absolute path of %{buffer_name} file
|
||||||
set -l src (path resolve $argv[1])
|
set -l src (path resolve $argv[1])
|
||||||
# exit if not a typst file
|
# exit if not a typst file
|
||||||
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
|
||||||
end
|
end
|
||||||
# change abs path to pdf extension
|
# change abs path to pdf extension
|
||||||
set -l targ (string replace '.typ' '.pdf' $src)
|
set -l targ (string replace '.typ' '.pdf' $src)
|
||||||
# get pdf target's base name
|
# get pdf target's base name
|
||||||
set -l base (path basename --no-extension $src).pdf
|
set -l base (path basename --no-extension $src).pdf
|
||||||
|
|
||||||
# if a suitable pdf exists in the same dir, open it
|
# if a suitable pdf exists in the same dir, open it
|
||||||
if test -f "$targ"
|
if test -f "$targ"
|
||||||
zopen "$targ"
|
zopen "$targ"
|
||||||
else
|
else
|
||||||
# no such file in current dir, time to search!
|
# no such file in current dir, time to search!
|
||||||
# if we're in a git repo, search from its root
|
# if we're in a git repo, search from its root
|
||||||
# if we're not, search from cwd
|
# if we're not, search from cwd
|
||||||
|
@ -142,7 +141,4 @@ function hx-typ-zathura
|
||||||
echo "$base couldn't be found at root $root!"
|
echo "$base couldn't be found at root $root!"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
hx-typ-zathura $argv
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue