[plug] enabling advanced bash tab completion and other neat things

Bernard Blackham bernard at blackham.com.au
Mon Dec 2 13:30:27 WST 2002


On Mon, Dec 02, 2002 at 12:50:38PM +0800, ryan at is.as.geeky.as wrote:
> Take them out, restart a shell and everything magically works :) 
> apt-get package completion, ssh hostname completion and all sorts of
> useful things.

Indeed! My favourites:

    * scp machine:<tab> (works best on local machines)
    * mysql <tab> (list of DBs)
    * make <tab> (targets)
    * tar xzvf tarball.tar.gz <tab> (lists the files in the tarball
      - dont do this on a kernel source or equally big tgz :)
    * cd /v/c/a/a<tab> (expands to /var/cache/apt/archives or
      whatever happens to match first)

These are all zsh ones though - bash will probably have something
comparable.  The list is endless
(/usr/share/zsh/*/functions/Completion).

And while we're sharing cool things ... one of the latest zsh's
(either 4.x or 4.0.6) now recognises escape sequences in the
RPROMPT, so I now have a colorful battery meter on my command prompt
without twisted vt100 codes to realign the cursor.  Simple as:

precmd() {
    BATT=`cat /proc/apm|cut -f7 -d " "|cut -f1 -d%`;
    if [ $BATT -le 5 ] ; then
        RPROMPT='%{^[[1;31m^G%}'    # red
    else
        if [ $BATT -le 9 ] ; then
            RPROMPT='%{^[[1;33m%}'  # yellow
        else
            RPROMPT='%{^[[1;32m%}'  # green
        fi
    fi
    RPROMPT="%* $RPROMPT$BATT%%%{^[[0m%}"
    export RPROMPT
}

Certainly could be done neater, but works. NB: each ^[ will have to
be replaced with an actual escape char, and ditto for ^G.

2.2c,

Bernard.

-- 
 Bernard Blackham
 bernard at blackham dot com dot au
 Australian Linux Technical Conference 2003: http://www.linux.conf.au/



More information about the plug mailing list