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

. slib

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

NOTE: save directory is ~/pics/screenshots
EOF

exit 0
}

check_program "scrot"

default_dir="${HOME}"/pics/screenshots

s_flg=""
while getopts "d:sh" option; do
	case "${option}" in
	d) input="${OPTARG}" ;;

	s) s_flg="1" ;;

	h) help ;;

	*) invalid_use -h ;;

	esac
done

shift $((OPTIND - 1))

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

[ -z "${input}" ] && input="${default_dir}"

outfile="${input}"

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

if [ ! -e "$(dirname "${outfile}")" ]; then
	mkdir -p "$(dirname "${outfile}")" > /dev/null 2>&1 \
	|| err "Failed to create directory"
fi

if [ "${s_flg}" = "1" ]; then
	run "scrot -zs ${outfile}" "${outfile}"
else
	run "scrot -z ${outfile}" "${outfile}"
fi