100 lines
2.6 KiB
Bash
Executable file
100 lines
2.6 KiB
Bash
Executable file
#!/bin/bash
|
|
# dunst-spmenu
|
|
# See included LICENSE file for more information.
|
|
|
|
getField() {
|
|
var="$(jq -r ".data[0][] | .${1:-summary.data}" < /tmp/dunst-spmenu-history)"
|
|
|
|
if [ -n "${var}" ]; then
|
|
printf "%s" "${var}"
|
|
fi
|
|
}
|
|
|
|
getCache() {
|
|
dunstctl history > /tmp/dunst-spmenu-history
|
|
}
|
|
|
|
clearCache() {
|
|
rm -f /tmp/dunst-spmenu-*
|
|
}
|
|
|
|
getData() {
|
|
declare -a icons
|
|
declare -a id
|
|
declare -a summary
|
|
declare -a body
|
|
|
|
getField icon_path.data > /tmp/dunst-spmenu-icon
|
|
getField id.data > /tmp/dunst-spmenu-data
|
|
getField summary.data > /tmp/dunst-spmenu-summary
|
|
getField body.data > /tmp/dunst-spmenu-body
|
|
|
|
mapfile -t icons < /tmp/dunst-spmenu-icon
|
|
mapfile -t id < /tmp/dunst-spmenu-data
|
|
mapfile -t summary < /tmp/dunst-spmenu-summary
|
|
mapfile -t body < /tmp/dunst-spmenu-body
|
|
|
|
maxlen="${#id[@]}"
|
|
i=0
|
|
|
|
while true; do
|
|
[ -n "${icons[i]}" ] && [ -f "${icons[i]}" ] && printf "img://%s\t" "${icons[i]}"
|
|
[ -n "${summary[i]}" ] && printf "\033[0;34m%s" "${summary[i]}"
|
|
[ -n "${body[i]}" ] && printf "\033[0m - %s" "${body[i]}"
|
|
|
|
[ "${maxlen}" -le "$i" ] && break
|
|
i=$((i+1))
|
|
printf "\n"
|
|
done
|
|
|
|
[ -z "${summary[0]}" ] && [ -z "${body[0]}" ] && printf "\033[0;34mNo notifications.\033[0m\n"
|
|
|
|
printf "\n\033[0;31mClear\n"
|
|
|
|
if [ "$(dunstctl is-paused)" = "false" ]; then
|
|
printf "\033[0;31mPause\n"
|
|
else
|
|
printf "\033[0;31mUnpause\n"
|
|
fi
|
|
}
|
|
|
|
main() {
|
|
pidof dunst >/dev/null || {
|
|
printf "dunst not running, can't view history.\n" > /dev/stderr
|
|
exit 1
|
|
}
|
|
|
|
getCache
|
|
|
|
declare -a id
|
|
getField id.data > /tmp/dunst-spmenu-data
|
|
mapfile -t id < /tmp/dunst-spmenu-data
|
|
|
|
numberOfNotifications="${#id[@]}"
|
|
|
|
getData | spmenu --print-index --lines 50 --columns 1 --display-icons --hide-powerline --hide-prompt --hide-input --hide-caps --hide-match-count --hide-pretext --hide-caret --hide-mode | sed -e 's/\x1b\[[0-9;]*m//g' > /tmp/dunst-spmenu-index
|
|
|
|
while read -r sel; do
|
|
case "$sel" in
|
|
"$((numberOfNotifications+2))")
|
|
printf "Cleared history.\n" > /dev/stderr
|
|
dunstctl history-clear
|
|
;;
|
|
"$((numberOfNotifications+3))")
|
|
printf "Toggled pause.\n" > /dev/stderr
|
|
dunstctl set-paused toggle
|
|
;;
|
|
"")
|
|
[ "$1" = "debug" ] || clearCache
|
|
exit 0
|
|
;;
|
|
*)
|
|
printf "Removed index %s\n" "${id[sel]}" > /dev/stderr
|
|
dunstctl history-rm "${id[sel]}"
|
|
;;
|
|
esac
|
|
done < /tmp/dunst-spmenu-index
|
|
}
|
|
|
|
main "$@"
|