From f25684b23bb7bf4dfd11640ae9e754ceaa7267ac Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Sun, 18 Sep 2022 18:11:42 -0500 Subject: [PATCH] feat(hypr): add keybind to save gifs --- dots/.config/hypr/scripts/screen-cap.bash | 27 +++++++++++++++++++++++ dots/.config/hypr/wm/bindings.conf | 1 + 2 files changed, 28 insertions(+) create mode 100755 dots/.config/hypr/scripts/screen-cap.bash diff --git a/dots/.config/hypr/scripts/screen-cap.bash b/dots/.config/hypr/scripts/screen-cap.bash new file mode 100755 index 00000000..733aa169 --- /dev/null +++ b/dots/.config/hypr/scripts/screen-cap.bash @@ -0,0 +1,27 @@ +#!/bin/bash + +mk-gif() { + local tmpfile + local program_name="Screen Capture" + local pid_file="/tmp/mk-gif-pid" + + if [[ -f "${pid_file}" ]]; then + notify-send "End ${program_name}" "Ending Screen Capture" -a "${program_name}" + if ! kill -SIGINT "$(cat /tmp/mk-gif-pid)"; then + notify-send "Failed ${program_name}" "Failed to Save Screen Capture" -u "critical" -a "${program_name}" + 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}" + else + notify-send "Start ${program_name}" "Starting Screen Capture" -a "${program_name}" + input_tmpfile="/tmp/$(mktemp wf-recorder.XXXXXXXXXXX).mp4" + wf-recorder -g "$(slurp)" -f "${input_tmpfile}" & + printf "%s" $! >"${pid_file}" + wait + yes | gifski "${input_tmpfile}" --output "${input_tmpfile}.gif" + cat "${input_tmpfile}.gif" | wl-copy --type image/gif + rm -f "${pid_file}" + fi +} + +mk-gif diff --git a/dots/.config/hypr/wm/bindings.conf b/dots/.config/hypr/wm/bindings.conf index 47d7dfb9..ca5fb185 100644 --- a/dots/.config/hypr/wm/bindings.conf +++ b/dots/.config/hypr/wm/bindings.conf @@ -60,6 +60,7 @@ bind=SUPER,Q,killactive, bind=SUPER,A,togglefloating, bind=SUPERSHIFT,Q,exec,swaylock bind=SUPER,S,exec,grim -g "$(slurp)" - | wl-copy +bind=SUPERSHIFT,S,exec,~/.config/hypr/scripts/screen-cap.bash bind=SUPERSHIFT,M,exit # Mediakey bindings as taken from `wev`