Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Post History

66%
+2 −0
Q&A An alternative to pacman sudo nag?

TL;DR When pacman bugs you for sudo, in bash or zsh (and possibly others but I haven't verified that), run sudo !! Full Answer As I see it you have 2 options: command substitution or an alias (o...

posted 9mo ago by TowerOfTurtles‭

Answer
#1: Initial revision by user avatar TowerOfTurtles‭ · 2024-02-19T00:43:39Z (9 months ago)
# TL;DR
When pacman bugs you for sudo, in bash or zsh (and possibly others but I haven't verified that), run `sudo !!`

# Full Answer
As I see it you have 2 options: command substitution or an alias (or new command entirely). Neither are a perfect solution but can help lessen the disruption to your flow.

## Command History Substitution
This doesn't stop pacman from requiring sudo, nor will it stop it from bugging you, but it will make rerunning it with sudo much easier. If you just ran `pacman -Syu` or some similar command that requires sudo and it nags you, you can run `sudo !!` and it will autocomplete to `sudo <whatever command you just executed>`.

For more info, see the relevant sections of the [bash manual](https://www.gnu.org/software/bash/manual/bash.html#Event-Designators) and [zsh manual](https://zsh.sourceforge.io/Doc/Release/Expansion.html#History-Expansion). (If anyone can verify that this works, or knows of a similar solution, for other shells, post a comment or edit this answer.)

## Make an Alias or New Command
You can define an alias in `~/.bashrc` (or `~/.bash_aliases` if there's a reference to it in .bashrc,) to whichever `pacman` command you want to use. For example:
- `alias pacs='sudo pacman -S'` or `alias pacmans='sudo pacman -S'`
- `alias pacr='sudo pacman -R'` or `alias pacmanr='sudo pacman -R'`
- `alias pacu='sudo pacman -U'` or `alias pacmanu='sudo pacman -U'`

This would require you to get muscle memory going to use these commands instead of `pacman -S`, etc., and it's not something that would carry over from one system to the next, but it would stop pacman from nagging you about sudo. This could, in theory, also conflict with other potential commands that might have the same name (though I don't know of any that would, off the top of my head).

Making a new command is almost exactly the same, except instead of defining it in .bashrc, you would make a new file somewhere in your path (i.e. any of the directories listed when you execute `echo $PATH`) and enter the text in the example aliases after the `=` (minus the `'`s) there.