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

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

while getopts "hwxd:s:o:" o; do case "${o}" in
  w)
    DMENU="tofi"
    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="tofi"
    DEFARGS="--prompt-text"
    SCRSH="grim"
  elif [ -n "$DISPLAY" ]; then
    DMENU="dmenu"
    DEFARGS="-p"
    SCRSH="maim"
  else
    output_text "Stuck" "Can't tell if Wayland or X, what gives?"
    exit 1
  fi
fi

sleep 0.3

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

sleep 0.1
"$SCRSH" $SARG "$TEMPFILE"

if [ -z "$FILENAME" ]; then
  FILENAME="$(echo "$TEMPFILE" | $DMENU $DARGS $DEFARGS "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"