From 5685b248febedc80ee9e02cd427f686461876e06 Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Sun, 18 Sep 2022 18:36:42 -0500 Subject: [PATCH] refactor(hypr): improve screen-cap code --- dots/.config/hypr/scripts/screen-cap.bash | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/dots/.config/hypr/scripts/screen-cap.bash b/dots/.config/hypr/scripts/screen-cap.bash index 768df3e7..9133b6ff 100755 --- a/dots/.config/hypr/scripts/screen-cap.bash +++ b/dots/.config/hypr/scripts/screen-cap.bash @@ -1,13 +1,22 @@ #!/bin/bash +# Dependencies: +# - wf-recorder: https://github.com/ammen99/wf-recorder +# - Gifski: https://github.com/ImageOptim/gifski +# - I do a conversion from mp4 to gif because there is various issues with recording straight to gif format with +# wf-recorder +# - notification daemon: https://archlinux.org/packages/?name=notification-daemon +# - wl-clipboard: https://github.com/bugaevc/wl-clipboard + mk-gif() { local program_name="Screen Capture" local pid_file="/tmp/mk-gif-pid" if [[ -f "${pid_file}" ]]; then notify-send "Saving ${program_name}" "This May Take a Minute" -a "${program_name}" - if ! kill -SIGINT "$(cat /tmp/mk-gif-pid)"; then + if ! kill -SIGINT "$(cat "${pid_file}")" 2>/dev/null; then notify-send "Failed ${program_name}" "Failed to Save Screen Capture" -u "critical" -a "${program_name}" + rm -rf "${pid_file}" exit 1 fi inotifywait -e delete_self /tmp/mk-gif-pid && notify-send "Saved ${program_name}" "Successfully Saved Screen Capture to Clipboard" -a "${program_name}" @@ -18,7 +27,7 @@ mk-gif() { wf-recorder -g "$(slurp)" -f "${input_tmpfile}" & printf "%s" $! >"${pid_file}" wait - yes | gifski "${input_tmpfile}" --output "${input_tmpfile}.gif" + gifski "${input_tmpfile}" --output "${input_tmpfile}.gif" wl-copy --type image/gif <"${input_tmpfile}.gif" rm -f "${pid_file}" fi