From: joey@hwi.ath.cx
To: zsh-workers@sunsite.dk, schizo@debian.org, ian@caliban.org
Subject: use tab-completion rules extracted from man page
Date: Wed, 5 May 2004 03:42:26 +0100 [thread overview]
Message-ID: <20040505024226.GA22722@hwi.ath.cx> (raw)
[-- Attachment #1: Type: text/plain, Size: 478 bytes --]
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 ]
[-- Attachment #2: autocomplete_from_man.sh.standalone.stripped --]
[-- Type: text/plain, Size: 1416 bytes --]
## 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 --<Tab>
## 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
next reply other threads:[~2004-05-05 14:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-05-05 2:42 joey [this message]
2004-05-05 15:05 ` Clint Adams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040505024226.GA22722@hwi.ath.cx \
--to=joey@hwi.ath.cx \
--cc=ian@caliban.org \
--cc=pclark@cs.bris.ac.uk \
--cc=schizo@debian.org \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).