AutoYADM commit: 2025-04-23 18:30:06
This commit is contained in:
parent
b65ff72e2c
commit
068b1da3c2
2 changed files with 124 additions and 118 deletions
|
@ -52,11 +52,13 @@ complete -c git-forgit -n '__fish_seen_subcommand_from checkout_file' -a "(__fis
|
||||||
complete -c git-forgit -n '__fish_seen_subcommand_from checkout_tag' -a "(__fish_git_tags)" -d Tag
|
complete -c git-forgit -n '__fish_seen_subcommand_from checkout_tag' -a "(__fish_git_tags)" -d Tag
|
||||||
complete -c git-forgit -n '__fish_seen_subcommand_from cherry_pick' -a "(complete -C 'git cherry-pick ')"
|
complete -c git-forgit -n '__fish_seen_subcommand_from cherry_pick' -a "(complete -C 'git cherry-pick ')"
|
||||||
complete -c git-forgit -n '__fish_seen_subcommand_from clean' -a "(__fish_git_files untracked ignored)"
|
complete -c git-forgit -n '__fish_seen_subcommand_from clean' -a "(__fish_git_files untracked ignored)"
|
||||||
|
complete -c git-forgit -n '__fish_seen_subcommand_from diff' -a "(complete -C 'git diff ')"
|
||||||
complete -c git-forgit -n '__fish_seen_subcommand_from fixup' -a "(__fish_git_local_branches)"
|
complete -c git-forgit -n '__fish_seen_subcommand_from fixup' -a "(__fish_git_local_branches)"
|
||||||
complete -c git-forgit -n '__fish_seen_subcommand_from log' -a "(complete -C 'git log ')"
|
complete -c git-forgit -n '__fish_seen_subcommand_from log' -a "(complete -C 'git log ')"
|
||||||
complete -c git-forgit -n '__fish_seen_subcommand_from reflog' -a "(complete -C 'git reflog ')"
|
complete -c git-forgit -n '__fish_seen_subcommand_from reflog' -a "(complete -C 'git reflog ')"
|
||||||
complete -c git-forgit -n '__fish_seen_subcommand_from rebase' -a "(complete -C 'git rebase ')"
|
complete -c git-forgit -n '__fish_seen_subcommand_from rebase' -a "(complete -C 'git rebase ')"
|
||||||
complete -c git-forgit -n '__fish_seen_subcommand_from reset_head' -a "(__fish_git_files all-staged)"
|
complete -c git-forgit -n '__fish_seen_subcommand_from reset_head' -a "(__fish_git_files all-staged)"
|
||||||
complete -c git-forgit -n '__fish_seen_subcommand_from revert_commit' -a "(__fish_git_commits)"
|
complete -c git-forgit -n '__fish_seen_subcommand_from revert_commit' -a "(__fish_git_commits)"
|
||||||
|
complete -c git-forgit -n '__fish_seen_subcommand_from show' -a "(complete -C 'git show ')"
|
||||||
complete -c git-forgit -n '__fish_seen_subcommand_from stash_show' -a "(__fish_git_complete_stashes)"
|
complete -c git-forgit -n '__fish_seen_subcommand_from stash_show' -a "(__fish_git_complete_stashes)"
|
||||||
complete -c git-forgit -n '__fish_seen_subcommand_from stash_push' -a "(__fish_git_files modified deleted modified-staged-deleted)"
|
complete -c git-forgit -n '__fish_seen_subcommand_from stash_push' -a "(__fish_git_files modified deleted modified-staged-deleted)"
|
||||||
|
|
|
@ -9,9 +9,10 @@
|
||||||
# Author: Daniel Fichtinger <daniel@ficd.ca
|
# Author: Daniel Fichtinger <daniel@ficd.ca
|
||||||
# License: MIT
|
# License: MIT
|
||||||
|
|
||||||
argparse q/quiet k/kill-on-exit h/help -- $argv
|
function hx-typ-zathura
|
||||||
|
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
|
||||||
|
@ -25,26 +26,26 @@ if test (count $argv) -eq 0; or set -q _flag_h
|
||||||
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!
|
||||||
|
@ -77,10 +78,10 @@ if set -q _flag_k
|
||||||
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
|
||||||
|
@ -96,10 +97,10 @@ function zopen --wraps 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")
|
||||||
|
@ -108,24 +109,24 @@ function find_pdf
|
||||||
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
|
||||||
|
@ -141,4 +142,7 @@ else
|
||||||
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