AutoYADM commit: 2025-05-18 19:11:24
This commit is contained in:
parent
cdd0ea1ace
commit
1affe9ad60
4 changed files with 34 additions and 63 deletions
|
@ -18,6 +18,3 @@ abbr -a blu systemctl --user restart blueman-applet.service
|
||||||
abbr -a hniri hx /home/fic/.config/niri/main.kdl
|
abbr -a hniri hx /home/fic/.config/niri/main.kdl
|
||||||
abbr -a hbf hut builds show --follow
|
abbr -a hbf hut builds show --follow
|
||||||
abbr -a k kak
|
abbr -a k kak
|
||||||
abbr -a krc kak -e \'cd ~/.config/kak\' ~/.config/kak/kakrc
|
|
||||||
abbr -a kakrc kak -e \'cd ~/.config/kak\' ~/.config/kak/kakrc
|
|
||||||
abbr -a kniri kak -e \'cd ~/.config/niri\' ~/.config/niri/main.kdl
|
|
||||||
|
|
3
.config/fish/functions/kakrc.fish
Normal file
3
.config/fish/functions/kakrc.fish
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
function kakrc
|
||||||
|
kak -e 'cd ~/.config/kak' ~/.config/kak/kakrc
|
||||||
|
end
|
3
.config/fish/functions/kniri.fish
Normal file
3
.config/fish/functions/kniri.fish
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
function kniri
|
||||||
|
kak -e 'cd ~/.config/niri' ~/.config/niri/main.kdl
|
||||||
|
end
|
|
@ -3,14 +3,13 @@
|
||||||
# hx-typ-zathura: easily preview your typst documents from Helix!
|
# hx-typ-zathura: easily preview your typst documents from Helix!
|
||||||
# This script will automatically find a pdf that matches your
|
# This script will automatically find a pdf that matches your
|
||||||
# current Typst document and attempt to open it with Zathura.
|
# current Typst document and attempt to open it with Zathura.
|
||||||
# Optionally, it will quit Zathura when you close Helix, and
|
# Optionally, it will quit Zathura when you close Helix.
|
||||||
# uses typst watch to continuously compile the file.
|
|
||||||
# Run this script with --help for usage info!
|
# Run this script with --help for usage info!
|
||||||
|
|
||||||
# Author: Daniel Fichtinger <daniel@ficd.ca
|
# Author: Daniel Fichtinger <daniel@ficd.ca
|
||||||
# License: MIT
|
# License: MIT
|
||||||
|
|
||||||
argparse q/quiet k/kill-on-exit w/watch h/help s/session -- $argv
|
argparse q/quiet k/kill-on-exit h/help p/process -- $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
|
||||||
|
@ -22,11 +21,7 @@ if test (count $argv) -eq 0; or set -q _flag_h
|
||||||
echo "Options:"
|
echo "Options:"
|
||||||
echo "-q/--quiet: Don't \`echo\` on caught errors, return 1 instead."
|
echo "-q/--quiet: Don't \`echo\` on caught errors, return 1 instead."
|
||||||
echo "-k/--kill-on-exit: Kill Zathura when parent Helix process exits."
|
echo "-k/--kill-on-exit: Kill Zathura when parent Helix process exits."
|
||||||
echo "-w/--watch: live preview mode"
|
|
||||||
echo "-h/--help: print this screen"\n
|
echo "-h/--help: print this screen"\n
|
||||||
echo "Note:"
|
|
||||||
echo "To avoid spawning a large number of typst processes,"
|
|
||||||
echo "--watch is only effective if --kill-on-exit is also set."\n
|
|
||||||
echo 'Author: Daniel Fichtinger <daniel@ficd.ca>'
|
echo 'Author: Daniel Fichtinger <daniel@ficd.ca>'
|
||||||
echo 'License: MIT'
|
echo 'License: MIT'
|
||||||
return 0
|
return 0
|
||||||
|
@ -48,70 +43,40 @@ function qecho
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# absolute path of %{buffer_name} file
|
|
||||||
set -g src_path (path resolve $argv[1])
|
|
||||||
|
|
||||||
# check if the user asked to kill zathura on helix exit
|
# check if the user asked to kill zathura on helix exit
|
||||||
# or to watch the pdf
|
|
||||||
if set -q _flag_k || set -q _flag_w
|
|
||||||
if set -q _flag_k
|
if set -q _flag_k
|
||||||
set kill_parent
|
set kill_parent
|
||||||
end
|
set client_id $_flag_p
|
||||||
if set -q _flag_w
|
# traverse up process tree to find caller Helix PID
|
||||||
set typst_watch
|
# We use this PID to kill zathura if Helix exits first!
|
||||||
|
# we only need to define this function
|
||||||
|
# inside this scope
|
||||||
|
function find_parent_process
|
||||||
|
echo "$client_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
if not set -q _flag_s
|
set parent_pid (find_parent_process hx)
|
||||||
qecho "You must provide --session=<name> with --kill-on-exit or --watch."
|
if test -z "$parent_pid"
|
||||||
|
qecho "Couldn't find parent hx process!"
|
||||||
return $ret
|
return $ret
|
||||||
end
|
end
|
||||||
set session_name $_flag_s
|
|
||||||
set session_socket "$XDG_RUNTIME_DIR/kakoune/$session_name"
|
|
||||||
if not test -S "$session_socket"
|
|
||||||
qecho "Session $session_name not found!"
|
|
||||||
return $ret
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
function monitor_kak
|
|
||||||
set -l socket $argv[1]
|
|
||||||
set -l zathura_pid $argv[2]
|
|
||||||
set -l typst_pid $argv[3]
|
|
||||||
|
|
||||||
set -l dir (path dirname "$socket")
|
|
||||||
set -l file (path basename "$socket")
|
|
||||||
|
|
||||||
inotifywait -q -e delete,delete_self,moved_from --format '%f' "$dir" | while read filename
|
|
||||||
if test "$filename" = "$file"
|
|
||||||
kill $zathura_pid &> /dev/null
|
|
||||||
if test -n "$typst_pid"
|
|
||||||
kill $typst_pid &>/dev/null
|
|
||||||
end
|
|
||||||
break
|
|
||||||
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
|
||||||
set -f pdf_path $argv[1]
|
# this should be set if the user asked to watch
|
||||||
# this should be set if the user asked to kill
|
|
||||||
if set -q kill_parent
|
if set -q kill_parent
|
||||||
# create background sub-process
|
# create background sub-process
|
||||||
# otherwise helix will hang
|
# otherwise helix will hang
|
||||||
begin
|
begin
|
||||||
zathura "$pdf_path" &>/dev/null &
|
zathura "$argv[1]" &>/dev/null &
|
||||||
set zathura_pid $last_pid
|
set zathura_pid $last_pid
|
||||||
if set -q typst_watch
|
waitpid -c 1 "$parent_pid" "$zathura_pid"
|
||||||
typst watch "$src_path" "$pdf_path" &>/dev/null &
|
kill $zathura_pid &>/dev/null
|
||||||
set -f typst_pid $last_pid
|
|
||||||
end
|
|
||||||
monitor_kak "$session_socket" "$zathura_pid" "$typst_pid" &
|
|
||||||
end &
|
end &
|
||||||
else
|
else
|
||||||
# user didn't ask for kill, so open normally
|
# user didn't ask for watch, so open normally
|
||||||
zathura "$pdf_path" &>/dev/null &
|
zathura "$argv[1]" &>/dev/null &
|
||||||
end
|
end
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
@ -128,17 +93,19 @@ function find_pdf
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# echo $src_path
|
# absolute path of %{buffer_name} file
|
||||||
|
set -l src (path resolve $argv[1])
|
||||||
|
# echo $src
|
||||||
# return 0
|
# return 0
|
||||||
# exit if not a typst file
|
# exit if not a typst file
|
||||||
if not string match -q '*.typ' $src_path
|
if not string match -q '*.typ' $src
|
||||||
qecho "$(path basename $src_path) 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 --regex '\.typ$' '.pdf' $src_path)
|
set -l targ (string replace --regex '\.typ$' '.pdf' $src)
|
||||||
# get pdf target's base name
|
# get pdf target's base name
|
||||||
set -l base (path basename --no-extension $src_path).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"
|
||||||
|
@ -160,3 +127,4 @@ else
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue