summaryrefslogtreecommitdiff
path: root/scripts/gui/shot
blob: a133c16eeb53c84a729bd951894c064ca89c7f14 (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
#!/bin/sh

. "lib_common.sh"
. "lib_handle.sh"

help() {
cat << EOF
${0}: Wrapper script to take screenshots
options:
 -d [File]       Write to File
 -s              Select the area with the cursor
 -w              Select the area with the cursor
 -h              Print this message and exit

NOTE: save directory is ~/media/photo/screenshot
EOF
exit 0
}

screenshot_handle check_program
default_dir="${XDG_SCREENSHOT_DIR:-${HOME}/media/photo/screenshot}"

mode="fullscreen"
while getopts "d:swh" option; do
	case "${option}" in
	d) input="${OPTARG}"     ;;
	s) mode="select"         ;;
	w) mode="focused-window" ;;
	h) help                  ;;

	*) invalid_use -h        ;;
	esac
done

shift $((OPTIND - 1))

[ ${#} != 0 ] && invalid_use

if [ -z "${input}" ]; then
	input="${default_dir}"
	mkdir -p "${default_dir}"
fi

outfile="${input}"

[ -d "${input}" ] && outfile="${input}/$(date '+%b%d::%H%M%S').png"

if [ ! -e "$(dirname "${outfile}")" ]; then
	mkdir -p "$(dirname "${outfile}")" ||
		err "Failed to create directory ${outfile}"
fi

if [ "${mode}" = "select" ]; then
	run --no-exit --reload-compositor \
		"screenshot_handle ${mode} ${outfile}" && echo "${outfile}"
else
	screenshot_handle "${mode}" "${outfile}" && echo "${outfile}"
fi