Some pacman functions require sudo. When I forget the sudo, you get:
error: you cannot perform this operation unless you are root.
I then have to press the keys:
up, home, s, u, d, o, space, enter to rerun with sudo. I find this irritating and it breaks my flow.
Is there a better solution here? If sudo is required for an operation, it should be run with sudo, rather than erroring out. In most situations where sudo is dangerous, it would prompt for a password anyway, so there's very little danger here. I have almost never ran pacman with sudo when I didn't mean to, but I have forgotten the sudo many times.
I could alias
sudo pacman. However, some operations don't need sudo, like
-Q. That alias would result in needless password prompts, which I also want to avoid.
How can I make pacman automatically use sudo when needed? I'd also like it to participate in sudo caching, so for example I don't want a situation like
systemctl which automatically asks for sudo password when needed, but fails to remember it.