summaryrefslogtreecommitdiff
path: root/scrshot
blob: e2703209c6bb248952dddeb7ccb1600374cc3a22 (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
#!/bin/sh

output_text () {
  notify-send "$1" "$2"
  printf "$2\n"
}

while getopts "hwxd:s:o:" o; do case "${o}" in
  w)
    DMENU="bemenu"
    SCRSH="grim"
    ;;
  x)
    DMENU="dmenu"
    SCRSH="maim"
    ;;
  d) DARG="$OPTARG $DARG" ;;
  s) SARG="$OPTARG $SARG" ;;
  o) FILENAME="$OPTARG" ;;
esac done

if [ -z "$DMENU" ]; then
  if [ -n "$WAYLAND_DISPLAY" ]; then
    DMENU="bemenu"
    SCRSH="grim"
  elif [ -n "$DISPLAY" ]; then
    DMENU="dmenu"
    SCRSH="maim"
  else
    output_text "Stuck" "Can't tell if Wayland or X, what gives?"
    exit 1
  fi
fi

TEMPNAME="$(mktemp -u | xargs basename)"
TEMPFILE="${TEMPNAME#tmp.}.png"

"$SCRSH" $SARG "$TEMPFILE"

if [ -z "$FILENAME" ]; then
  FILENAME="$(echo "$TEMPFILE" | $DMENU $DARGS -p "What to name the file?")"
  if [ -z "$FILENAME" ]; then
    rm -rf "$TEMPFILE"
    output_text "Deleted" "No filename selected, file deleted!"
    exit
  fi
fi

mv "$TEMPFILE" "$FILENAME"