#! /usr/bin/bash set -euo pipefail IFS=$'\n\t' listopts() { echo "📷 Focused monitor" echo "📷 Focused monitor → 📋" echo "📷 Select region" echo "📷 Select region → 📋" echo "📷 Focused window" echo "📷 Focused window → 📋" echo "📷 Select window" echo "📷 Select window → 📋" echo "📽 Record focused monitor" echo "📽 Record select region" echo "📽 Record focused window" echo "📽 Record select window" } ts() { date +'%Y%m%dT%H%M%S' } screenshot_filename() { echo ~/Pictures/screenshots/screenshot-"$(ts)".png } recording_filename() { echo ~/Pictures/screenshots/recording-"$(ts)".mp4 } if [ -z "${1+exists}" ]; then option=$(listopts | fuzzel --dmenu) else option="$1" fi get_focused_monitor() { swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name' } get_focused_window() { swaymsg -t get_tree | jq -j '.. | select(.type?) | select(.focused).rect | "\(.x),\(.y) \(.width)x\(.height)"' } select_window() { swaymsg -t get_tree | jq -r '.. | select(.pid? and .visible?) | .rect | "\(.x),\(.y) \(.width)x\(.height)"' | slurp } case "${option}" in "everything") grim "$(screenshot_filename)";; "📷 Focused monitor") grim -o "$(get_focused_monitor)" "$(screenshot_filename)";; "📷 Focused monitor → 📋") grim -o "$(get_focused_monitor)" - | wl-copy;; "📷 Select region") grim -g "$(slurp)" "$(screenshot_filename)";; "📷 Select region → 📋") grim -g "$(slurp)" - | wl-copy;; "📷 Focused window") grim -g "$(get_focused_window)" "$(screenshot_filename)";; "📷 Focused window → 📋") grim -g "$(get_focused_window)" - | wl-copy;; "📷 Select window") grim -g "$(select_window)" "$(screenshot_filename)";; "📷 Select window → 📋") grim -g "$(select_window)" - | wl-copy;; "📽 Record focused monitor") wf-recorder -o "$(get_focused_monitor)" -f "$(recording_filename)";; "📽 Record select region") wf-recorder -g "$(slurp)" -f "$(recording_filename)";; "📽 Record focused window") wf-recorder -g "$(get_focused_window)" -f "$(recording_filename)";; "📽 Record select window") wf-recorder -g "$(select_window)" -f "$(recording_filename)";; esac