grim-wrapper: add output name to filename and allow out path override

This commit is contained in:
Kevin Baensch 2025-03-22 00:00:51 +01:00
parent 7da04253c3
commit 4c5c775258
Signed by: derped
GPG key ID: C0F1D326C7626543

View file

@ -5,7 +5,8 @@ let
grim-wrapper =
pkgs.writeShellScript "grim-wrapper" # bash
''
OUTPUT_DIR="$(${pkgs.xdg-user-dirs}/bin/xdg-user-dir PICTURES)"
OUTPUT_DIR="''${OUTPUT_DIR:-$(${pkgs.xdg-user-dirs}/bin/xdg-user-dir PICTURES)}";
OUTPUT_NAME="''${OUTPUT_NAME:-}";
DATE="$(${pkgs.coreutils}/bin/date +'%Y-%m-%d;%H:%M:%S;')";
WINDOW_LIST="$(${pkgs.sway-unwrapped}/bin/swaymsg -t get_tree | ${pkgs.jq}/bin/jq -r '.. | select(.pid? and .visible?) | "\(.rect.x+.window_rect.x),\(.rect.y+.window_rect.y) \(.window_rect.width)x\(.window_rect.height) \(.app_id):\(.name)"' | ${pkgs.coreutils}/bin/tr -d '"/;\\')";
@ -16,7 +17,7 @@ let
SELECTION="$(${pkgs.slurp}/bin/slurp -d -f "''${SELECTION_FORMAT}" <<< ''${WINDOW_LIST})";
SELECTION_AREA="$(${pkgs.jq}/bin/jq -r '.area' <<< "''${SELECTION}")";
SELECTION_NAME="$(${pkgs.jq}/bin/jq -r '.name' <<< "''${SELECTION}"| ${pkgs.coreutils}/bin/tr ' ' '_')";
OUTNAME="''${OUTPUT_DIR}/''${DATE}''${SELECTION_NAME}.png";
OUTNAME="''${OUTPUT_DIR}/''${OUTPUT_NAME:-''${DATE}''${SELECTION_NAME}}.png";
${pkgs.grim}/bin/grim -g "''${SELECTION_AREA}" "''${OUTNAME}";
;;
clip)
@ -26,7 +27,7 @@ let
*)
DISPLAY="$(${pkgs.sway-unwrapped}/bin/swaymsg -t get_outputs | ${pkgs.jq}/bin/jq -r '.[] | select(.focused) | .name')";
DISPLAY_RES="$(${pkgs.sway-unwrapped}/bin/swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .current_mode | "\(.width)x\(.height)"')";
OUTNAME="''${OUTPUT_DIR}/''${DATE}''${DISPLAY_RES};''${DISPLAY};.png"
OUTNAME="''${OUTPUT_DIR}/''${OUTPUT_NAME:-''${DATE}''${DISPLAY_RES};''${DISPLAY};}.png"
${pkgs.grim}/bin/grim -o "''${DISPLAY}" "''${OUTNAME}";
;;
esac;