Tuesday, January 17, 2012

How to install packages fast from command line - updated

I prefer using command line for installing packages. I think it is easier, faster and makes me feel a geek. :) Anyway, typing always apt-get install/remove/update or aptitude install/remove/whatever is not too convenient and takes too much time. This is where aliases come into the picture. In my .bash_aliases file (/home/username/.bash_aliases), I defined the following aliases:


alias supdate="sudo aptitude update"
alias supgrade="sudo aptitude upgrade"
alias sfull-upgrade="sudo aptitude full-upgrade"
alias sinstall="sudo aptitude install"
alias sremove="sudo aptitude remove"
alias spurge="sudo aptitude purge"
alias ssearch="aptitude search"


Note, that my .bashrc file refers to the .bash_aliases as (I think it is a default setting in Debian):

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi


So, now, instead of typing sudo aptitude update, I just type supdate and my system is going to update itself. Since I'am the only user of my system I let myself install/remove/update/... packages using sudo without any password. It just makes my life much easier. 

O.K. So far, so good. But what about bash completion that does not work with aliases by default? It is easier to type sinstall than sudo aptitude install, yes, that is O.K. But to remember the exact package name is, well, at least not the easiest task. Not even for a geek wannabe. Especially, if you install more than 3 packages. No worry, though. By inserting the following lines into your .bashrc, this problem can be overcome easily:

complete -F _pkg_names -o default sinstall
complete -F _pkg_names -o default sremove
complete -F _pkg_names -o default spurge


That's it. Yes, I know it could be solved in a much elegant way, but anyhow, it works. :)

Of course, in order to use bash completion, you need to install the bash-completion package first. 

Update: _pkg_names is provided by devscripts.

No comments:

Post a Comment