Unsecured Boundaries
Pages :: Home - Papers - Contact - Bookmarks -
Tags ::All - Australie - Kernel - Linux - Misc - Ruby - Ssh -

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.

Recent updates

Bookmarks

(Last edited on Fri Sep 30, 2011) – tagged in (no tags)

Read…

Thinkpad x60s : passer en SXGA+ :)[fr]

(Last edited on Thu Sep 29, 2011) – tagged in (no tags)

Read…

Boot

(Last edited on Thu Sep 01, 2011) – tagged in Linux,misc

Read…

Home

(Last edited on Thu Sep 01, 2011) – tagged in (no tags)

Read…

Code and content available in this website is published under the terms of the GPL licence unless mentioned overwise.