Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm using Arch Linux. I have packer installed for AUR packages, but I want to be able to use the pacman command for both. I think I will need a function for this -- what I mean is that whenever I use pacman, it will try using packer and if that fails (invalid option) it will use pacman-color. It could also decide which program to use based on the arguments. I can't just use packer (alias pacman='sudo packer') because packer doesn't have some options like -R to remove packages. I want to always use it to install and upgrade packages however, because It can install from the default repositories as well as AUR.

Does someone know how to accomplish this, or could point me in the right direction? I'm new to bash scripting.

Thanks.

EDIT: I tried pacman () { sudo packer $@ || sudo pacman-color $@ }, the only problem is if packer fails it prints the error (e.g. pacman -V prints packer: Option '-V' is not valid.).

share|improve this question
    
It's certainly possible to write a wrapper as you're suggesting but it would require someone who's familiar with the usage of both commands (which I am not). –  David Z Jul 6 '10 at 2:39

1 Answer 1

up vote 1 down vote accepted

I figured it out myself. This works nicely (in .bashrc or .zshrc or whatever):

pacman() {
    if [[ $1 = -h* || $1 = "--help" ]]; then
        echo "pacman help:\n"
        /usr/bin/pacman -h
        echo "\n\npacker help:\n"
        packer -h
    elif [[ $1 = -V* || $1 = -Q* ]]; then
        pacman-colour "$@"
    elif [[ $1 = -Si*  || $1 = -Ss* ]]; then
        packer "$@"
    elif [[ ( $1 != -Sy $1 != -Sc* && $1 = -S* ) || $1 = -G* ]]; then
        sudo packer "$@"
    else
        sudo pacman-color "$@"
    fi
}

EDIT: Actually the developer made something called pacwrap which does the job better.

It doesn't use sudo unless it has to, and chooses either pacman or packer based on the operations used.

share|improve this answer
    
The $@ should be quoted to preserve word splitting/escapes correctly: "$@" –  Daenyth Jul 6 '10 at 21:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.