63 lines
1.3 KiB
Fish
Executable file
63 lines
1.3 KiB
Fish
Executable file
#!/usr/bin/env fish
|
|
|
|
argparse q/quiet -- $argv
|
|
|
|
function z --wraps zathura
|
|
zathura "$argv[1]" &>/dev/null &
|
|
end
|
|
|
|
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" != ''
|
|
z "$candidate"
|
|
else
|
|
return 1
|
|
end
|
|
end
|
|
|
|
if set -q _flag_q
|
|
set ret 1
|
|
else
|
|
set ret 0
|
|
end
|
|
|
|
function qecho
|
|
if not set -q _flag_q
|
|
echo $argv[1]
|
|
end
|
|
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
|
|
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 &
|
|
z "$targ"
|
|
else
|
|
# no such file in current dir, time to search!
|
|
# if we're in a git repo, search from root
|
|
# if we're not, search from cwd
|
|
if git rev-parse --is-inside-work-tree &>/dev/null
|
|
# echo in git
|
|
set root (git rev-parse --show-toplevel)
|
|
# echo $root
|
|
else
|
|
echo out git
|
|
set root (pwd)
|
|
end
|
|
if not find_pdf "$root" "$base"
|
|
if set -q _flag_q
|
|
return 1
|
|
else
|
|
echo "$base couldn't be found!"
|
|
end
|
|
end
|
|
end
|