-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnextApts
More file actions
executable file
·75 lines (73 loc) · 2.19 KB
/
Copy pathnextApts
File metadata and controls
executable file
·75 lines (73 loc) · 2.19 KB
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
# script to get all appointments in the next 24 hours
apts=$(calcurse -d 2 | grep -v -e '^$' -e '^[0-9]' ) # get apts from the next 2 days
n=$(calcurse -d 2 | grep -c -v -e '^$' -e '^[0-9]' ) # line length
nh=0 #counter for hours/minutes
nn=0 #counter for names
isBreak=false
# save all appts in arrays
for i in $(seq 1 "${n}"); do
if ${isBreak}
then
isBreak=false
continue
fi
if [ $((i%2)) -eq 0 ]; then
names[nn]=$(echo "${apts}" | sed -n "${i}"p)
nn=$((nn+1))
else
hcheck=$(echo "${apts}" | sed -n "${i}"p | cut -d' ' -f3 | cut -d: -f1)
if [ "${hcheck}" = ".." ]
then
isBreak=true
continue
fi
hours[nh]=${hcheck}
while echo "${hours[${nh}]#0}" | grep -e '^0[0-9]+$' > /dev/null 2>&1
do
hours[nh]=${hours[${nh}]#0}
done
minutes[nh]=$(echo "${apts}" | sed -n "${i}"p | cut -d' ' -f3 | cut -d: -f2)
while echo "${minutes[${nh}]#0}" | grep -e '^0[0-9]*$' > /dev/null 2>&1
do
minutes[nh]=${minutes[${nh}]#0}
done
nh=$((nh+1))
fi
done
cHour=$(date +%-H)
while echo "${cHour}" | grep -e '^0[0-9]+$' > /dev/null 2>&1
do
cHour=${cHour#0}
done
cMin=$(date +%-M)
while echo "${cMin}" | grep -e '^0[0-9]+$' > /dev/null 2>&1
do
cMin=${cMin#0}
done
#print next apts for day 1
n1=$(calcurse -d 1 | grep -c -e '- [0-9]' ) # length of day 1
for i in $(seq 0 $((n1-1))); do
if [ "${hours[${i}]}" -gt "${cHour}" ]; then
if [ "${minutes[${i}]}" -ge "${cMin}" ]; then
printf "[%02d:%02d] ${names[${i}]}\n" $((hours[i]-cHour)) $((minutes[i]-cMin))
else
printf "[%02d:%02d] ${names[${i}]}\n" $((hours[i]-cHour-1)) $((60-cMin+minutes[i]))
fi
elif [ "${hours[${i}]}" -eq "${cHour}" ]; then
if [ "${minutes[${i}]}" -gt "${cMin}" ]; then
printf "[00:%02d] ${names[${i}]}\n" $((minutes[i]-cMin))
fi
fi
done
#print next apts for day 2
for i in $(seq "${n1}" $((nh-1))); do
if [ "${hours[${i}]}" -le "${cHour}" ]; then
if [ "${minutes[${i}]}" -ge "${cMin}" ]; then
printf "[%02d:%02d] ${names[${i}]}\n" $((24-cHour+hours[i])) $((minutes[i]-cMin))
else
printf "[%02d:%02d] ${names[${i}]}\n" $((24-cHour+hours[i]-1)) $((60-cMin+minutes[i]))
fi
fi
done
calcurse -t