dotfiles-scripts/ScreenShot/screengrab

51 lines
1.1 KiB
Plaintext
Raw Normal View History

2024-09-23 14:48:57 +02:00
#!/bin/bash
SAVE_DIR="$HOME/Pictures/Screenshots"
mkdir -p "$SAVE_DIR"
FILENAME="$SAVE_DIR/screenshot_$(date +"%Y-%m-%d_%H-%M-%S").png"
capture_full_screen() {
grim "$FILENAME"
}
capture_selection() {
region=$(slurp)
grim -g "$region" "$FILENAME"
}
capture_window() {
window_geometry=$(swaymsg -t get_tree | jq -r '.. | select(.focused?) | .rect | "\(.x),\(.y) \(.width)x\(.height)"')
grim -g "$window_geometry" "$FILENAME"
}
2025-01-09 14:18:58 +01:00
open_editor() {
# Open the screenshot in GIMP, ImageMagick's display command, or any preferred editor
photoflare "$FILENAME" &
}
# Capture the screenshot based on the option passed
2024-09-23 14:48:57 +02:00
case "$1" in
--full)
capture_full_screen
;;
--select)
capture_selection
;;
--window)
capture_window
;;
*)
2025-01-09 14:18:58 +01:00
echo "Invalid option. Usage: screengrab [--full|--select|--window] [--edit]"
2024-09-23 14:48:57 +02:00
exit 1
;;
esac
2025-01-09 14:18:58 +01:00
# Copy to clipboard and notify
2024-09-23 14:48:57 +02:00
wl-copy < "$FILENAME" && notify-send "Screengrab" "Screenshot copied to clipboard"
2025-01-09 14:18:58 +01:00
# If --edit flag is passed, open the screenshot in the editor
if [[ "$2" == "--edit" ]]; then
open_editor
fi