summaryrefslogtreecommitdiff
path: root/polybar/scripts/screenshot-menu.sh
blob: b3064a9dc3c8d7f37ce5591185278aaa0b5b0c79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/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"