From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10026 invoked from network); 5 May 2004 14:02:11 -0000 Received: from thor.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.86) by ns1.primenet.com.au with SMTP; 5 May 2004 14:02:11 -0000 Received: (qmail 28842 invoked from network); 5 May 2004 14:01:48 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 5 May 2004 14:01:48 -0000 Received: (qmail 12487 invoked by alias); 5 May 2004 14:01:43 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 19880 Received: (qmail 10405 invoked from network); 5 May 2004 02:55:01 -0000 Received: from thor.dotsrc.org (HELO a.mx.sunsite.dk) (qmailr@130.225.247.86) by sunsite.dk with SMTP; 5 May 2004 02:54:58 -0000 Received: (qmail 23032 invoked from network); 5 May 2004 02:54:58 -0000 Received: from 82-32-4-230.cable.ubr01.azte.blueyonder.co.uk (HELO hwi.ath.cx) (82.32.4.230) by a.mx.sunsite.dk with SMTP; 5 May 2004 02:54:55 -0000 Received: from joey by hwi.ath.cx with local (Exim 3.36 #1 (Debian)) id 1BLCMc-0007JZ-00; Wed, 05 May 2004 03:42:26 +0100 Date: Wed, 5 May 2004 03:42:26 +0100 To: zsh-workers@sunsite.dk, schizo@debian.org, ian@caliban.org Subject: use tab-completion rules extracted from man page Message-ID: <20040505024226.GA22722@hwi.ath.cx> Reply-To: Paul Joey Clark Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="2oS5YaxWCcQjTEyO" Content-Disposition: inline User-Agent: Mutt/1.5.5.1+cvs20040105i From: joey@hwi.ath.cx X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: **** X-Spam-Status: No, hits=4.3 required=6.0 tests=NO_REAL_NAME,RCVD_IN_DYNABLOCK, RCVD_IN_SORBS autolearn=no version=2.63 X-Spam-Hits: 4.3 --2oS5YaxWCcQjTEyO Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Greetings elite shell hackers! I wrote this script to extract all the - and -- options of any program from its man page, and use them as possible words for completion. I saw the good work in /etc/bash_completion, and in zsh/.../Completion, and I thought you might be interested in this slant. It doesn't display the meanings of the options, but it does work in the general case, without human-defined rules. -- Joey [ who likes writing shellscripts: http://hwi.ath.cx/jsh ] --2oS5YaxWCcQjTEyO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="autocomplete_from_man.sh.standalone.stripped" ## autocomplete_from_man: Adds to bash or zsh the ability to use tab-completion for the - and -- options of the current command (provided it has a man page installed). ## eg.: source this script with ". ./autocomplete_from_man", then type: tar -- ## Documented code available from http://hwi.ath.cx extractregex () { if [ "$1" = -atom ] then shift; EXPR="$@" else EXPR="(""$@"")" fi perl -n -e ' while ( /'"$EXPR"'/g ) { print("$1\n"); } ' } extractpossoptsfrommanpage () { 'man' "$@" 2> /dev/null | col -bx | extractregex -atom "[ ]((-|--)[A-Za-z0-9-=]+)" } if [ "$BASH" ] then function joeyComplete { COMMAND="$1" CURRENT=${COMP_WORDS[COMP_CWORD]} WORDS="--help "` extractpossoptsfrommanpage "$COMMAND" ` complete -W "$WORDS" -a -b -c -d -f -g -j -k -s -u "$COMMAND" COMPREPLY=(`compgen -W "$WORDS" -a -b -c -d -f -g -j -k -s -u -- "$CURRENT"`) } complete -F joeyComplete ` echo "$PATH" | tr ':' '\n' | while read DIR; do find "$DIR" -type f -maxdepth 1; done | sed 's+.*/++' ` fi if [ "$ZSH_NAME" ] then mkdir -p /tmp/completion_options function joeyComplete { read -c COMMAND ARGS if [ ! "$ARGS" ] then reply= else MEMOFILE=/tmp/completion_options/"$COMMAND".cached if [ ! -f "$MEMOFILE" ] || [ "$REMEMO" ] then extractpossoptsfrommanpage "$COMMAND" > "$MEMOFILE" fi reply=(--help `cat "$MEMOFILE"`) fi } compctl -f -c -u -r -K joeyComplete -H 0 '' "*" -tn fi --2oS5YaxWCcQjTEyO--