8d58994d765de350f1dc66132eaab0358e10a4ab

Author
Matthieu Baerts <matttbe@gmail.com>
Committer
GitHub <noreply@github.com>
Date

Message

feat(zbell): add option not to use notify-send (#10082)

Diff

 1diff --git a/plugins/zbell/README.md b/plugins/zbell/README.md
 2index 1c1c13546647a40051df702d606bdb9fc2cea6e2..eb87699c4d98f617b09096009c318215e4ca056b 100644
 3--- a/plugins/zbell/README.md
 4+++ b/plugins/zbell/README.md
 5@@ -24,6 +24,9 @@ These settings need to be set in your zshrc file, before Oh My Zsh is sourced.
 6   zbell_ignore=($EDITOR $PAGER)
 7   ```
 8 
 9+- `zbell_use_notify_send`: If set to `true`, `notify-send` tool is used -- if
10+  available -- to display a popup on the screen. Default: `true` (enabled).
11+
12 ## Author
13 
14 Adapted from an original version by [Jean-Philippe Ouellet](https://github.com/jpouellet).
15diff --git a/plugins/zbell/zbell.plugin.zsh b/plugins/zbell/zbell.plugin.zsh
16index 6d0416502a6d680b379e9f480acb0472d2464e70..8e374029b76993f4acba04914983ffff3966d79a 100644
17--- a/plugins/zbell/zbell.plugin.zsh
18+++ b/plugins/zbell/zbell.plugin.zsh
19@@ -29,18 +29,31 @@ autoload -Uz regexp-replace || return
20 # initialize zbell_ignore if not set
21 (( ${+zbell_ignore} )) || zbell_ignore=($EDITOR $PAGER)
22 
23+# initialize zbell_use_notify_send if not set
24+(( ${+zbell_use_notify_send} )) || zbell_use_notify_send=true
25+
26 # initialize it because otherwise we compare a date and an empty string
27 # the first time we see the prompt. it's fine to have lastcmd empty on the
28 # initial run because it evaluates to an empty string, and splitting an
29 # empty string just results in an empty array.
30 zbell_timestamp=$EPOCHSECONDS
31 
32+# UI notification function
33+# $1: command
34+# $2: duration in seconds
35+zbell_ui_notify() {
36+	[[ $zbell_use_notify_send != "true" ]] && return
37+
38+	if type notify-send > /dev/null; then
39+		notify-send -i terminal "Command completed in ${2}s:" $1
40+	fi
41+}
42+
43 # default notification function
44 # $1: command
45 # $2: duration in seconds
46 zbell_notify() {
47-	type notify-send > /dev/null && \
48-		notify-send -i terminal "Command completed in ${2}s:" $1
49+	zbell_ui_notify "${@}"
50 	print -n "\a"
51 }
52