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?
2 Answers
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.
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.

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