Pacman Notification

I think elementary OS have built into their system that when apt has finished it’s current action you are given a notification. This is helpful when you are building or compiling a package and it means you can carry on without having to check the terminal for any further input constantly.

Has anyone come across something similar for Pacman?

1 Like

Pamac, but you categorically reject that :slight_smile:

1 Like

There is only a beep hook - AUR (en) - pacman-beep-hook

I tried creating a hook:

pacman-dunst-post.hook

[Trigger]
Operation = Install
Operation = Upgrade
Operation = Remove
Type = Package
Target = *

[Action]
Description = Pacman dunst
Depends = dunst
When = PostTransaction
Exec = dbus-launch /usr/bin/dunstify -i 0 -t 2000 -u critical 'Transaction OK'

but it works only from a super user, and I need dunst to run from a normal user.
Don’t know how to do (

1 Like

Should be easy to write a script around the update cmd. Something like,

$ cat sys-update
#!/bin/bash

yay -Syu

status=$?

[ $status -eq 0 ] && notify-send -t 10 -u normal -a pacman "Pacman update has completed successfully" || notify-send -t 10 -u critical -a pacman "Pacman update FAILED"
2 Likes

I do. I like a terminal. elementary’s notification happens via any terminal commands as well.

@Vedun and @chroot both good ideas and I will take a look.

2 Likes

I like chroot’s suggestion best, you can even go as far as wrapping pacman with a bit of scripting and calling the script the same.

~/.local/bin/pacman

#!/bin/bash

# simple pacman wrapper script to send a notification when updating or installing


typeset -i update=0 install=0

if ! hash tee sudo notify-send >/dev/null 2>&1; then
	echo "error: this script requires notify-send, sudo, and tee"
	exit 1
fi

notify()
{
	if (( $1 == 0 )); then
		notify-send -t 3000 -u normal -a pacman "Pacman $2 Complete"
	else
		notify-send -t 5000 -u critical -a pacman "Pacman $2 FAILED" \
			"$(sed -e "s/\x1b\[.\{1,5\}m//g" /tmp/pacman-output)"
	fi
}

# we only care about -S and -u operations, any use of -u will be
# considered an update (even when installing a package alongside the update)
while getopts ":Su" OPT; do
	case $OPT in
		S) install=1 ;;
		u) (( install )) && update=1 ;;
		*) ;;
	esac
done

# hand it off to pacman regardless
sudo /usr/bin/pacman "$@" 2> >(tee /tmp/pacman-output)
rcode=$?

# if we did an update or an install we notify
if (( update )); then
	notify $rcode "Update"
elif (( install )); then
	notify $rcode "Install"
fi
rm /tmp/pacman-output

exit $rcode
4 Likes

Top @natemaia

1 Like

Brilliant, thanks @natemaia I’ll take a look.

1 Like