-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathblobcatd
82 lines (66 loc) · 1.84 KB
/
blobcatd
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
76
77
78
79
80
81
82
#!/bin/bash
# some vars and defaults
VERSION="0.1"
character="cat"
TIME=60s
CONFIG_DIR="$HOME/.config/blobcatd"
oneshot () {
# get a list of strings
strings="$(grep -Ev '^$' $CONFIG_DIR/${character}/strings)"
# get one string out of it
message=$(echo "$strings" | shuf -n 1)
# pick an image
image=$(find "$CONFIG_DIR/${character}" -type f -exec file --mime-type {} \+ | awk -F: '{if ($2 ~/image\//) print $1}' | shuf -n 1)
# and send a notification
notify-send -a blobcatd -i "${image}" "blobcatd" "${message}"
}
loop () {
# this is a *daemon*, by design, so it should never stop?
while true; do
oneshot
sleep "${TIME}"
done
}
help () {
cat << NYAOF
blobcatd - by gravitos
inspired in this post: https://wetdry.world/@gravitos/111063551410060977
version ${VERSION}
args:
-h this
-c choose your fighter- i mean, character. these are stored in ~/.config/blobcatd
-C specify config dir
-o run only once (useful when using with cron or other timers)
-v get version
-t wait time between each notifications
(Pause for NUMBER seconds. SUFFIX may be 's' for seconds (the default), 'm' for minutes, 'h' for hours or 'd' for days. NUMBER need not be an integer. Given two or more arguments, pause for the amount of time specified by the sum of their values.) - man sleep
NYAOF
}
main() {
runtype=loop
# commandline option stuff
local flag
while getopts ":c:C:ohvt:" flag
do
case ${flag} in
# help!
h) help
exit
;;
# do you want to use a blobfox
c) character=${OPTARG};;
C) CONFIG_DIR=${OPTARG};;
o) runtype=oneshot;;
# version
v) echo "blobcatd version ${VERSION}"
exit;;
# wait time
t) export TIME=${OPTARG};;
# and the other stuff
?) echo "invalid option: ${flag}"
exit;;
esac
done
$($runtype)
}
main "$@"