Skip to content

Commit 8698223

Browse files
feat: add the ability to send notification through Pushover (#57)
This commit adds the ability for people to send notifications through [pushover](https://pushover.net/). --------- Co-authored-by: Mathieu Tanguay <[email protected]>
1 parent 06f7038 commit 8698223

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Tmux plugin to notify you when processes are finished.
2222
* [Change monitor update period](#change-monitor-update-period)
2323
* [Add additional shell suffixes](#add-additional-shell-suffixes)
2424
* [Enable telegram channel notifications](#enable-telegram-channel-notifications)
25+
* [Enable Pushover notifications](#enable-pushover-notifications)
2526
* [Execute custom notification commands](#execute-custom-notification-commands)
2627
* [How does it work](#how-does-it-work)
2728
* [Other use cases](#other-use-cases)
@@ -110,7 +111,7 @@ The Tmux notify script uses your shell prompt suffix to check whether a command
110111
> \[!WARNING]\
111112
> This feature requires [wget](https://www.gnu.org/software/wget/) to be installed on your system.
112113
113-
By default, the tool only sent operating system notifications. It can, however, also send a message to a user-specified telegram channel.
114+
By default, the tool only sends operating system notifications. It can, however, also send a message to a user-specified telegram channel.
114115

115116
> Put `set -g @tnotify-telegram-bot-id 'your telegram bot id'` and `set -g @tnotify-telegram-channel-id 'your channel id'` in the `.tmux.conf` config file to enable this.
116117
@@ -125,6 +126,20 @@ Additionally, you can use the `set -g @tnotify-telegram-all 'on'` option to send
125126
> \[!NOTE]\
126127
> You can get your telegram bot id by creating a bot using [BotFather](https://core.telegram.org/bots#6-botfather) and your channel id by sending your channel invite link to the `@username_to_id_bot` bot.
127128
129+
### Enable Pushover notifications
130+
131+
> \[!WARNING]\
132+
> This feature requires [curl](https://curl.se/) to be installed on your system.
133+
134+
By default, the tool only sends operating system notifications. It can, however, also send a message to a user-specified pusher user or group.
135+
136+
> Put `set -g @tnotify-pushover-token 'your pushover application token'` and `set -g @tnotify-pushover-user 'your pushover user or group identifier'` in the `.tmux.conf` config file to enable this.
137+
138+
> You may optionally put `set -g @tnotify-pushover-title 'The title of the message'` to override the default title
139+
140+
> \[!NOTE]\
141+
> You can create a free pushover account at [pushover.net](https://pushover.net/).
142+
128143
### Execute custom notification commands
129144

130145
You can execute a custom command after a process has finished by putting `set -g @tnotify-custom-cmd 'your custom command here'` in the `.tmux.conf` file. The custom command is executed in the pane where the process has finished. If you want to execute multiple commands, you can also put them in a bash script and execute this script (i.e. `set -g @tnotify-custom-cmd 'bash /path/to/script.sh'`).

scripts/helpers.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,36 @@ telegram_available() {
4848
[ -n "$telegram_id" ] && [ -n "$telegram_chat_id" ]
4949
}
5050

51+
# Check if pushover token and pushover user are set
52+
pushover_available() {
53+
local pushover_token="$(get_tmux_option "$tmux_notify_pushover_token" "$tmux_notify_pushover_token_default")"
54+
local pushover_user="$(get_tmux_option "$tmux_notify_pushover_user" "$tmux_notify_pushover_user_default")"
55+
[ -n "$pushover_token" ] && [ -n "$pushover_user" ]
56+
}
57+
5158
# Send telegram message
5259
# Usage: send_telegram_message <bot_id> <chat_id> <message>
5360
send_telegram_message() {
5461
wget --spider "https://api.telegram.org/bot$1/sendMessage?chat_id=$2&text=${3// /%20}" &> /dev/null
5562
}
5663

64+
# Send a message over https://pushover.net/
65+
# Usage: send_pushover_message <token> <user_id> <title> <message>
66+
# token is the application token on pushover.net
67+
# user_id is the user or group id of whom will receive the notification
68+
# the title of the message: https://pushover.net/api#registration
69+
# message is the message sent
70+
send_pushover_message() {
71+
curl -X POST --location "https://api.pushover.net/1/messages.json" \
72+
-H "Content-Type: application/json" \
73+
-d "{
74+
\"token\": \"$1\",
75+
\"user\": \"$2\",
76+
\"message\": \"$4\",
77+
\"title\": \"$3\"
78+
}" &> /dev/null
79+
}
80+
5781
# Send notification
5882
# Usage: notify <message> <title> <send_telegram>
5983
notify() {
@@ -81,6 +105,13 @@ notify() {
81105
telegram_chat_id="$(get_tmux_option "$tmux_notify_telegram_channel_id" "$tmux_notify_telegram_channel_id_default")"
82106
send_telegram_message $telegram_bot_id $telegram_chat_id "$1"
83107
fi
108+
109+
if pushover_available; then
110+
local pushover_token="$(get_tmux_option "$tmux_notify_pushover_token" "$tmux_notify_pushover_token_default")"
111+
local pushover_user="$(get_tmux_option "$tmux_notify_pushover_user" "$tmux_notify_pushover_user_default")"
112+
local pushover_title="$(get_tmux_option "$tmux_notify_pushover_title" "$tmux_notify_pushover_title_default")"
113+
send_pushover_message "$pushover_token" "$pushover_user" "$pushover_title" "$1"
114+
fi
84115

85116
# trigger visual bell
86117
# your terminal emulator can be setup to set URGENT bit on visual bell

scripts/variables.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,11 @@ export tmux_notify_telegram_all="@tnotify-telegram-all"
3939
export tmux_notify_telegram_bot_id_default=""
4040
export tmux_notify_telegram_channel_id_default=""
4141
export tmux_notify_telegram_all_default="off"
42+
43+
# Pushover notification settings
44+
export tmux_notify_pushover_token="@tnotify-pushover-token"
45+
export tmux_notify_pushover_user="@tnotify-pushover-user"
46+
export tmux_notify_pushover_title="@tnotify-pushover-title"
47+
export tmux_notify_pushover_token_default=""
48+
export tmux_notify_pushover_user_default=""
49+
export tmux_notify_pushover_title_default="Tmux Notify"

0 commit comments

Comments
 (0)