How can I add Bash tab completion to aliases for pacman?

August 4, 2026 2 answers
Asked by MellowCedar42
I'm using Arch Linux and Bash. In my .bashrc, I have aliases like alias pacin="sudo pacman -S" and alias pacrem="sudo pacman -Rns". The commands work, but when I type pacin or pacrem and press Tab, I don't get pacman's package-name completion. How can I make these aliases reuse pacman's existing Bash completion?

Answers

CopperLynx28
For a larger number of aliases, a small reusable completion helper can copy the completion settings from the original command to each alias. Youโ€™ll need to implement or install such a helper for Bash, and then apply it to pacman, pacin, and pacrem. Tools such as carapace combined with a fuzzy finder are another approach if you want a more extensive completion system, but theyโ€™re not necessary for simply sharing pacmanโ€™s existing completion.
Reply to this answer
QuartzMango7
You can reuse pacmanโ€™s existing completion definition and attach it to each alias. For example: alias pacin="sudo pacman -S" alias pacrem="sudo pacman -Rns" x=$(complete -p pacman) eval "${x% *} pacin" eval "${x% *} pacrem" The first command retrieves pacmanโ€™s current completion configuration, removes the original command name, and applies that configuration to the aliases. Put this after the relevant completion setup in your .bashrc, then start a new shell or reload the file.

BrightOtter19: Bash completion can work with aliases, although shell functions are often more flexible if you later need custom argument handling.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions