Add colors and bash-completion to aptitude
Colors
Aptitude output is not always very clear, and lacks a few colors, especially when you’re used to Gentoo. The following is a quick & easy way to get colors by filtering the output of `aptitude search`.
Simply define the following function in your ~/.bashrc:
(make sure you have the package “bash-completion” insalled, see below).
aptsearch () { # Search and highlight keyword in the restuls export GREP_COLOR='1' # Remove regexp patterns from the keyword to highlight keyword=`echo -n "$1" | sed -e 's/[^[:alnum:]|-]//g'` echo_bold "Highlight keyword: $keyword" aptitude search "$1" --disable-columns | egrep --color "$keyword"# Use the matching results to complete our install command matching=$(aptitude search --disable-columns -F "%p" "$1" | tr '\n' ' ') count=0 for i in $matching ; do count=$((count + 1)) done complete -W '$matching' aptinstall echo_bold "(Matching packages: $count)" if ! [ -z $2 ] ; then echo -e "$matching" | egrep --color=always "$keyword" fi }
Bash completion
Most of the time, when you search for something with “aptitude search”, you’ll end-up installing something that you found in the results.
The previous function defines a bash completion list for the alias aptinstall defined as follow (in your ~/.bashrc again):
alias aptinstall='sudo aptitude install'
You will now be able to get completion of the package names using aptinstall.