-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpush
More file actions
executable file
·70 lines (56 loc) · 1.55 KB
/
push
File metadata and controls
executable file
·70 lines (56 loc) · 1.55 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
#!/bin/sh
set -e
this_binary=${0##*/}
PO_URI="https://api.pushover.net/1/messages.json"
. ~/.config/pushover/pushover.env
priority=0
usage() {
cat <<EOF
Usage: $this_binary [OPTIONS]
$this_binary sends a message via pushover.net
Options:
-h, --help Print this help message.
-t, --title Message title (optional, defaults to \$(whoami)@\$(hostname))
-b, --body The message body (optional, defaults to stdin)
-p, --priority The message priority (-2, -1, 0, 1, defaults to 0)
-m, --monospace Print the message in monospace
EOF
}
opts=$(getopt -o ht:b:p:m -l help,title:,message:,body:,priority:,monospace -- "$@")
[ $? -eq 0 ] || { usage ; exit 1; }
eval set -- "$opts"
while true ; do
case "$1" in
--title|-t) title="$2";;
--body|-b) body="$2";;
--priority|-p) priority="$2";;
--monospace|-m) mono=1;;
--help|-h) usage; exit 0;;
--) break;;
esac
shift
done
case $priority in
-2|-1|0|1) ;;
*)
echo "invalid priority"
usage
exit 1
;;
esac
if [ -z "${body}" ] ; then
[ -t 0 ] && echo "Enter message (Enter, then CTRL+D to send):" 1>&2
body="$(cat)"
fi
if [ -z "${body}" ] ; then
echo message body must not be empty
usage
exit 1
fi
curl --silent "${PO_URI}" \
--form-string "user=${PO_USER}" \
--form-string "token=${PO_TOKEN}" \
--form-string "monospace=${mono:-0}" \
--form-string "title=${title:-$(whoami)@$(hostname)}" \
--form-string "priority=${priority}" \
--form-string "message=${body}"