aboutsummaryrefslogtreecommitdiff
path: root/modules/user/desktop/scripts/screenshot.sh
blob: 8250f9e22bccf9c917d271d11a9a3b0f76f883a1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/env bash
# Bash screenshot script. Requires grim, slurp, sway, fuzzel, libnotify and jq.
[[ -d "~/Pictures/Screenshots" ]] || mkdir -p ~/Pictures/Screenshots
IFS=$'\n'
screenshot_targets=$(swaymsg -rt get_outputs | jq -r '.[].name' | sort)
screenshot_targets+=($'\nSpecific region') # i LOVE bash
selected_target="$(printf '%s' "${screenshot_targets[@]}" | fuzzel --hide-prompt --mesg='What would you like to screenshot?' --mesg-mode=expand --minimal-lines --dmenu)"
outfile="$HOME/Pictures/Screenshots/$(date +'%F_%H.%M.%S.png')"

send_notification() {
    notify-send "Screenshot taken" "Screenshot saved to <b>$1</b>."
}

case $selected_target in
    'Specific region') grim -g "$(slurp)" "$outfile" && send_notification "$outfile";;
    *) grim -o "$selected_target" "$outfile" && send_notification "$outfile" ;;
esac