Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check notification service before enable #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions auto-notify.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,25 @@ function _auto_notify_reset_tracking() {
unset AUTO_COMMAND
}

function _has_notification_service() {
# Check dbus-send command exists
if ! type dbus-send > /dev/null; then
# perhaps it should run notify-send
print "unknown"
return
fi
local interfaces="$(dbus-send --session \
--type=method_call \
--print-reply \
--dest=org.freedesktop.DBus \
/org/freedesktop/DBus org.freedesktop.DBus.ListNames)"
if [[ $interfaces == *"org.freedesktop.Notifications"* ]]; then
print "yes"
else
print "no"
fi
}

function disable_auto_notify() {
add-zsh-hook -D preexec _auto_notify_track
add-zsh-hook -D precmd _auto_notify_send
Expand All @@ -164,6 +183,8 @@ platform="$(uname)"
if [[ "$platform" == "Linux" ]] && ! type notify-send > /dev/null; then
printf "'notify-send' must be installed for zsh-auto-notify to work\n"
printf "Please install it with your relevant package manager\n"
elif [[ "$platform" == "Linux" ]] && [[ "$(_has_notification_service)" == "no" ]]; then
# do not enable
else
enable_auto_notify
fi