#!/usr/bin/env bash set -euo pipefail dir="${XDG_PICTURES_DIR:-$HOME/Pictures}/Screenshots" mkdir -p "$dir" 2>/dev/null || true if [ ! -w "$dir" ]; then dir="/tmp" fi export DISPLAY="${DISPLAY:-:0}" if [ -z "${XAUTHORITY:-}" ] && [ -r "$HOME/.Xauthority" ]; then export XAUTHORITY="$HOME/.Xauthority" fi notify() { if command -v dunstify >/dev/null 2>&1; then dunstify -a polybar -u low "Screenshot" "$1" fi } menu() { printf '%s\n' full selection window | dmenu -i -p screenshot \ -fn "FiraCode Nerd Font-14" \ -nb "#282828" -nf "#ebdbb2" \ -sb "#d79921" -sf "#282828" } file="$dir/shot-$(date +%Y%m%d-%H%M%S).png" choice="$(menu)" case "$choice" in full) if command -v scrot >/dev/null 2>&1; then scrot "$file" elif command -v import >/dev/null 2>&1; then import -window root "$file" else notify "No screenshot tool found" exit 1 fi ;; selection) if command -v flameshot >/dev/null 2>&1; then flameshot gui -p "$dir" exit 0 elif command -v maim >/dev/null 2>&1; then maim -s "$file" elif command -v scrot >/dev/null 2>&1; then scrot -s "$file" elif command -v import >/dev/null 2>&1; then import "$file" else notify "No selection screenshot tool found" exit 1 fi ;; window) if command -v scrot >/dev/null 2>&1; then scrot -u "$file" elif command -v import >/dev/null 2>&1; then import "$file" else notify "No window screenshot tool found" exit 1 fi ;; *) exit 0 ;; esac notify "$file"