nixos-config/modules/home/wms/programs/grimsnap/default.nix

34 lines
961 B
Nix
Raw Normal View History

{ config, lib, pkgs, ... }:
2024-12-10 17:54:39 -05:00
{
home.packages = with pkgs; lib.mkIf config.home.desktop.enable [
(pkgs.writeScriptBin "grimsnap" ''
2024-12-10 17:54:39 -05:00
# Freeze the screen using hyprpicker
hyprpicker -r -z &
2024-12-10 17:54:39 -05:00
HYPRPICKER_PID=$!
sleep 0.1
# Select area
GEOM=$(slurp -w 3 -c ${config.look.colors.prime} -B 00000066 -b 00000099)
2024-12-10 17:54:39 -05:00
# Check selection is canceled
if [ -z "$GEOM" ]; then
kill $HYPRPICKER_PID 2>/dev/null
notify-send -t 3000 -a grim "Error" "No area selected."
2024-12-10 17:54:39 -05:00
exit 1
fi
# Define screenshot destination
FILE="''${XDG_PICTURES_DIR:-$HOME/Pictures}/Screenshots/$(date -Ins).png"
# Save and edit screenshot
grim -g "$GEOM" "$FILE"
# Notify user that the screenshot is saved
notify-send -a grim "Screenshot" "Area saved to $FILE" -i "$FILE"
# Kill picker after selection
kill %1 2>/dev/null
'')
];
}