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

dunstctl: script, module & preview images #362

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
30 changes: 30 additions & 0 deletions polybar-scripts/dunst-controller/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# dunstctl, a dunst controller script & module

This script is written in [`fish`](https://fishshell.com/), and displays a bell
icon that can be used to interact with [`dunst`](https://github.com/dunst-project/dunst)
via `dunstctl`, and utilises `dunstify` to send notifications.

Click to show historic notifications, middle-click to mute/unmute notifications,
and right-click to dismiss all. Double left click will show all notification history.

`chmod +x $HOME/.config/polybar/scripts/dunstctl.sh` (or the path of your choice.)

## Preview

![dunst](dunstctl-0.png)
![dunst-pause](dunstctl-1.png)

![dunst-notif](dunstctl-2.png)

## Example module

```ini
[module/dunstctl]
click-left = dunstctl history-pop
click-middle = $HOME/.config/polybar/scripts/dunstctl.sh toggle
click-right = dunstctl close-all
double-click-left = $HOME/.config/polybar/scripts/dunstctl.sh show-all
exec = $HOME/.config/polybar/scripts/dunstctl.sh
interval = 1.6
type = custom/script
```
44 changes: 44 additions & 0 deletions polybar-scripts/dunst-controller/dunstctl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#! /usr/bin/env fish

function unmute
dunstctl set-paused false && \
dunstify 'dunst' 'Unmuted notifications.' -i polari -u low &
end

function mute
dunstify 'dunst' 'Muting notifications...' -i polari -u low &
# We're about to mute notifications, so the above notification will
# effectively not show, since set-paused hides notifications. So, sleep
# for 2 seconds.
sleep 2
# Close all to prevent notification from showing up once we unmute.
dunstctl close-all
dunstctl set-paused true
end

function pop_all
for id in (dunstctl history | jq -r '.data[][].id.data')
dunstctl history-pop $id
end
end

if test (dunstctl is-paused) = "true"
switch $argv[1]
case 'toggle'
unmute
case 'show-all'
unmute
pop_all
case '*'
echo ' '(dunstctl count waiting)
end
else
switch $argv[1]
case 'toggle'
mute
case 'show-all'
pop_all
case '*'
echo ''
end
end
Binary file added polybar-scripts/dunst-controller/dunstctl-0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added polybar-scripts/dunst-controller/dunstctl-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added polybar-scripts/dunst-controller/dunstctl-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions polybar-scripts/dunst-controller/dunstctl.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[module/dunstctl]
click-left = dunstctl history-pop
click-middle = $HOME/.config/polybar/scripts/dunstctl.sh toggle
click-right = dunstctl close-all
double-click-left = $HOME/.config/polybar/scripts/dunstctl.sh show-all
exec = $HOME/.config/polybar/scripts/dunstctl.sh
interval = 1.6
type = custom/script
50 changes: 50 additions & 0 deletions polybar-scripts/dunst-controller/dunstctl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#! /usr/bin/env sh

unmute() {
dunstctl set-paused false && \
dunstify 'dunst' 'Unmuted notifications.' -i polari -u low &
}

mute() {
dunstify 'dunst' 'Muting notifications...' -i polari -u low &
# We're about to mute notifications, so the above notification will
# effectively not show, since set-paused hides notifications. So, sleep
# for 2 seconds.
sleep 2
# Close all to prevent notification from showing up once we unmute.
dunstctl close-all
dunstctl set-paused true
}

pop_all() {
dunstctl history | jq '.data[][].id.data' | while IFS= read -r id; do
dunstctl history-pop "$id"
done
}

if [ "$(dunstctl is-paused)" = 'true' ]; then
case $1 in
toggle)
unmute
;;
show-all)
unmute
pop_all
;;
*)
echo " $(dunstctl count waiting)"
;;
esac
else
case $1 in
toggle)
mute
;;
show-all)
pop_all
;;
*)
echo ''
;;
esac
fi