File: sxmo_timer.sh

package info (click to toggle)
sxmo-utils 1.14.2-1.1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 6,016 kB
  • sloc: sh: 9,166; ansic: 117; makefile: 68
file content (75 lines) | stat: -rwxr-xr-x 1,114 bytes parent folder | download
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
74
75
#!/bin/sh
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2022 Sxmo Contributors
# title="$icon_clk Timer"
# include common definitions
# shellcheck source=scripts/core/sxmo_common.sh
. sxmo_common.sh

timerrun() {
	TIME="$(
		echo "$@" |
		sed 's/\([^0-9]\)\([0-9]\)/\1+\2/g; s/h/*60m/g; s/m/*60s/g; s/s//g' |
		bc
	)"

	DATE1="$(($(date +%s) + TIME))";
	while [ "$DATE1" -ge "$(date +%s)" ]; do
		printf "%s\r" "$(date -u --date @$((DATE1 - $(date +%s))) +%H:%M:%S)";
		sleep 0.1
	done
	echo "Done with $*"

	while : ;
		do notify-send  "Done with $*";
		sxmo_vibrate 1000
		sleep 0.5
	done
}

stopwatchrun() {
	start="$(date +%s)"
	while : ; do
		time="$(($(date +%s) - start))"
		printf '%s\r' "$(date -u -d "@$time" +%H:%M:%S)"
	done
	sleep 0.1
}

menu() {
	TIMEINPUT="$(sxmo_dmenu_with_kb.sh -p Timer <<EOF
Stopwatch
1h
10m
9m
8m
7m
6m
5m
4m
3m
2m
1m
30s
Close Menu
EOF
	)" || exit
	case "$TIMEINPUT" in
		"Close Menu")
			exit 0
			;;
		"Stopwatch")
			sxmo_terminal.sh "$0" stopwatchrun
			;;
		*)
			sxmo_terminal.sh "$0" timerrun "$TIMEINPUT"
			;;
	esac
}

if [ $# -gt 0 ]
then
	"$@"
else
	menu
fi