| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | |
| 4 | source "$(dirname "$0")/_lib.sh" |
| 5 | dir=${SCREENSHOT_DIR:-$(xdg-user-dir PICTURES 2>/dev/null || echo "$HOME/Pictures")/Screenshots} |
| 6 | mkdir -p "$dir" |
| 7 | file="$dir/$(date +%Y-%m-%d_%H-%M-%S).png" |
| 8 | |
| 9 | case $1 in |
| 10 | area|edit) |
| 11 | geom=$(slurp -d -b '#1e1e2e88' -c '#b4befeff' -s '#b4befe22' -w 2) || exit 0 ;; |
| 12 | screen) |
| 13 | output=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name') |
| 14 | geom="" ;; |
| 15 | window) |
| 16 | geom=$(swaymsg -t get_tree | jq -r '.. | select(.focused?) | .rect | "\(.x),\(.y) \(.width)x\(.height)"') ;; |
| 17 | *) echo "usage: $0 area|screen|window|edit"; exit 1 ;; |
| 18 | esac |
| 19 | |
| 20 | if [[ $1 == screen ]]; then |
| 21 | grim -o "$output" "$file" |
| 22 | else |
| 23 | grim -g "$geom" "$file" |
| 24 | fi || { notify shot dialog-error "Screenshot failed"; exit 1; } |
| 25 | |
| 26 | wl-copy --type image/png < "$file" |
| 27 | |
| 28 | if [[ $1 == edit ]] && has swappy; then |
| 29 | swappy -f "$file" -o "$file" |
| 30 | fi |
| 31 | |
| 32 | |
| 33 | action=$(notify-send -a "Screenshot" -i "$file" -t 5000 \ |
| 34 | -A open=Open -A folder="Show folder" \ |
| 35 | "Screenshot saved" "${file/#$HOME/\~} (copied)" 2>/dev/null) |
| 36 | case $action in |
| 37 | open) xdg-open "$file" ;; |
| 38 | folder) xdg-open "$dir" ;; |
| 39 | esac |