Unix3r

Build. Break. Learn. Repeat.

Starting0%
Skip to content

unix3r/dotfiles

Public
main
U Unix3r Initial commit: sway + waybar dotfiles (Catppuccin Mocha) eb290df
39 lines · 1.3 KB Raw History
1#!/usr/bin/env bash
2# screenshot.sh area|screen|window|edit
3# Saves to $SCREENSHOT_DIR (default ~/Pictures/Screenshots) and copies to clipboard.
4source "$(dirname "$0")/_lib.sh"
5dir=${SCREENSHOT_DIR:-$(xdg-user-dir PICTURES 2>/dev/null || echo "$HOME/Pictures")/Screenshots}
6mkdir -p "$dir"
7file="$dir/$(date +%Y-%m-%d_%H-%M-%S).png"
8
9case $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 ;;
18esac
19
20if [[ $1 == screen ]]; then
21 grim -o "$output" "$file"
22else
23 grim -g "$geom" "$file"
24fi || { notify shot dialog-error "Screenshot failed"; exit 1; }
25
26wl-copy --type image/png < "$file"
27
28if [[ $1 == edit ]] && has swappy; then
29 swappy -f "$file" -o "$file"
30fi
31
32# Notification with "open" action (mako supports actions)
33action=$(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)
36case $action in
37 open) xdg-open "$file" ;;
38 folder) xdg-open "$dir" ;;
39esac