* use tab-completion rules extracted from man page
@ 2004-05-05 2:42 joey
2004-05-05 15:05 ` Clint Adams
0 siblings, 1 reply; 2+ messages in thread
From: joey @ 2004-05-05 2:42 UTC (permalink / raw)
To: zsh-workers, schizo, ian
[-- 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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: use tab-completion rules extracted from man page
2004-05-05 2:42 use tab-completion rules extracted from man page joey
@ 2004-05-05 15:05 ` Clint Adams
0 siblings, 0 replies; 2+ messages in thread
From: Clint Adams @ 2004-05-05 15:05 UTC (permalink / raw)
To: Paul Joey Clark; +Cc: zsh-workers, ian
> 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.
The _arguments function can already extract options from the --help
output of the program, though not the manpage.
> compctl -f -c -u -r -K joeyComplete -H 0 '' "*" -tn
compctl is the old, deprecated method of zsh programmable completion. You
may want to look into the new, function-based (compsys) method to
achieve your ends.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-05-05 15:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-05 2:42 use tab-completion rules extracted from man page joey
2004-05-05 15:05 ` Clint Adams
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).