* bash completion functions
@ 2003-01-28 9:18 Oliver Kiddle
2003-01-28 9:25 ` Zefram
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Oliver Kiddle @ 2003-01-28 9:18 UTC (permalink / raw)
To: Zsh workers
Attached is the bash completion emulation as promised. I've called the
function which enables the system bashcompinit so if you have an idea
for a better name, please say now. Which directory should it go in? I
was thinking just the Completion directory. It contains three
functions. compgen and complete correspond to the bash builtins.
_bash_complete is a wrapper function which gets run from the zsh
completion system. It requires 4.1, mainly because I stuff the
arguments all into the _comps array elements so for the 4.0 back port
(which I will do), I'll have to use a separate (_bash_comps) array.
The only things I've knowingly left unimplemented is completion for
jobs (because compgen is always run in a subshell) and complete -r
(because I couldn't be bothered). Actually compdef perhaps ought to
have -L and -r (remove) options. I've also commented out support for
the last compgen argument which is something I'm a little unsure about.
Also, $COMP_POINT might be iffy but it never seems to be used anyway.
Finally bash's compgen -C option does something weird so either it is
buggy or I don't understand but I've gone mostly by the documentation
there.
If you want to attempt to source the bash_completion project, the
following may help a little.
# their have function doesn't work in zsh (unset -v)
have() {
unset have
(( ${+commands[$1]} )) && have=yes
}
# shopt is bash's setopt
alias shopt=':'
# resolve function name clash (if you don't use autoload -U)
alias _expand=_bash_expand
# these are the options I seem to need to best emulate bash. Some may be
# missing and noshglob is questionable (but solved a specific issue)
emulate -L sh
setopt kshglob noshglob braceexpand
Oliver
#autoload
_bash_complete() {
local ret=1
local -a suf matches
local COMP_POINT COMP_CWORD
local -a COMP_WORDS COMPREPLY BASH_VERSINFO
local COMP_LINE="$words"
(( COMP_POINT = ${#${(j. .)words}} + $$#QIPREFIX + $#IPREFIX + $#PREFIX ))
(( COMP_CWORD = CURRENT - 1))
COMP_WORDS=( $words )
BASH_VERSINFO=( 2 05b 0 1 release )
[[ ${argv[${argv[(I)nospace]:-0}-1]} = -o ]] && suf=( -S '' )
matches=( ${(f)"$(compgen $@)"} )
if [[ -n $matches ]]; then
if [[ ${argv[${argv[(I)filenames]:-0}-1]} = -o ]]; then
compset -P '*/' && matches=( ${matches##*/} )
compset -S '/*' && matches=( ${matches%%/*} )
compadd -f "${suf[@]}" -a matches && ret=0
else
compadd "${suf[@]}" -a matches && ret=0
fi
fi
if (( ret )); then
if [[ ${argv[${argv[(I)default]:-0}-1]} = -o ]]; then
_default "${suf[@]}" && ret=0
elif [[ ${argv[${argv[(I)dirnames]:-0}-1]} = -o ]]; then
_directories "${suf[@]}" && ret=0
fi
fi
return ret
}
compgen() {
local opts prefix suffix ret=1 OPTARG OPTIND
local -a name res results
local -A shortopts
emulate -L sh
setopt kshglob noshglob braceexpand nokshautoload
shortopts=(
a alias b builtin c command d directory e export f file
g group j job k keyword u user v variable
)
while getopts "o:A:G:C:F:P:S:W:X:abcdefgjkuv" name; do
case $name in
[abcdefgjkuv]) OPTARG="${shortopts[$name]}" ;&
A)
case $OPTARG in
alias) results+=( "${(k)aliases[@]}" ) ;;
arrayvar) results+=( "${(k@)parameters[(R)array*]}" ) ;;
binding) results+=( "${(k)widgets[@]}" ) ;;
builtin) results+=( "${(k)builtins[@]}" "${(k)dis_builtins[@]}" ) ;;
command)
results+=(
"${(k)commands[@]}" "${(k)aliases[@]}" "${(k)builtins[@]}"
"${(k)functions[@]}" "${(k)reswords[@]}"
)
;;
directory)
setopt bareglobqual
results+=( ${IPREFIX}${PREFIX}*${SUFFIX}${ISUFFIX}(N-/) )
setopt nobareglobqual
;;
disabled) results+=( "${(k)dis_builtins[@]}" ) ;;
enabled) results+=( "${(k)builtins[@]}" ) ;;
export) results+=( "${(k)parameters[(R)*export*]}" ) ;;
file)
setopt bareglobqual
results+=( ${IPREFIX}${PREFIX}*${SUFFIX}${ISUFFIX}(N) )
setopt nobareglobqual
;;
function) results+=( "${(k)functions[@]}" ) ;;
group)
emulate zsh
_groups -U -O res
emulate sh
setopt kshglob noshglob braceexpand
results+=( "${res[@]}" )
;;
hostname)
emulate zsh
_hosts -U -O res
emulate sh
setopt kshglob noshglob braceexpand
results+=( "${res[@]}" )
;;
keyword) results+=( "${(k)reswords[@]}" ) ;;
setopt|shopt) results+=( "${(k)options[@]}" ) ;;
signal) results+=( "SIG${^signals[@]}" ) ;;
user) results+=( "${(k)userdirs[@]}" ) ;;
variable) results+=( "${(k)parameters[@]}" ) ;;
helptopic|job|running|stopped) ;;
esac
;;
F)
COMPREPLY=()
$OPTARG "${words[0]}" "${words[CURRENT-1]}" "${words[CURRENT-2]}"
results+=( "${COMPREPLY[@]}" )
;;
G)
setopt nullglob
results+=( ${~OPTARG} )
unsetopt nullglob
;;
W) eval "results+=( $OPTARG )" ;;
C) results+=( $(eval $OPTARG) ) ;;
P) prefix="$OPTARG" ;;
S) suffix="$OPTARG" ;;
X)
if [[ ${OPTARG[0]} = '!' ]]; then
results=( "${(M)results[@]:#${OPTARG#?}}" )
else
results=( "${results[@]:#$OPTARG}" )
fi
;;
esac
done
# support for the last, `word' option to compgen. Not particularly valuable
# and without it zsh matching can do a better job. Comment in if needed.
#shift $(( OPTIND - 1 ))
#(( $# )) && results=( "${(M)results[@]:#$1*}" )
print -l -- "$prefix${^results[@]}$suffix"
}
complete() {
emulate -L zsh
local args void cmd print remove
args=( "$@" )
zparseopts -D -a void o: A: G: W: C: F: P: S: X: a b c d e f g j k u v \
p=print r=remove
if [[ -n $print ]]; then
for cmd print in ${(kv)_comps[(R)_bash*]}; do
print "complete ${print#* } $cmd"
done
elif [[ -n $remove ]]; then
print "not implemented: -r option"
else
compdef _bash_complete\ ${(j. .)${(q)args[1,-1-$#]}} "$@"
fi
}
unfunction bashcompinit
autoload -U bashcompinit
return 0
This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: bash completion functions
2003-01-28 9:18 bash completion functions Oliver Kiddle
@ 2003-01-28 9:25 ` Zefram
2003-01-28 16:42 ` Bart Schaefer
2003-02-03 12:51 ` Clemens Fischer
2 siblings, 0 replies; 8+ messages in thread
From: Zefram @ 2003-01-28 9:25 UTC (permalink / raw)
To: Oliver Kiddle; +Cc: zsh-workers
Oliver Kiddle wrote:
>Also, $COMP_POINT might be iffy but it never seems to be used anyway.
...
> (( COMP_POINT = ${#${(j. .)words}} + $$#QIPREFIX + $#IPREFIX + $#PREFIX ))
That "$$" looks suspicious.
-zefram
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: bash completion functions
2003-01-28 9:18 bash completion functions Oliver Kiddle
2003-01-28 9:25 ` Zefram
@ 2003-01-28 16:42 ` Bart Schaefer
2003-01-29 10:17 ` Oliver Kiddle
2003-02-03 12:51 ` Clemens Fischer
2 siblings, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2003-01-28 16:42 UTC (permalink / raw)
To: Zsh workers
On Jan 28, 10:18am, Oliver Kiddle wrote:
} Subject: bash completion functions
}
} The only things I've knowingly left unimplemented is completion for
} jobs (because compgen is always run in a subshell)
We could do something about this, generically, by saving local copies of
the jobstates and jobtexts hashes in _main_complete or some such.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: bash completion functions
2003-01-28 16:42 ` Bart Schaefer
@ 2003-01-29 10:17 ` Oliver Kiddle
2003-01-29 11:16 ` Peter Stephenson
0 siblings, 1 reply; 8+ messages in thread
From: Oliver Kiddle @ 2003-01-29 10:17 UTC (permalink / raw)
To: Bart Schaefer; +Cc: Zsh workers
[-- Attachment #1: Type: text/plain, Size: 4333 bytes --]
On 28 Jan, Bart wrote:
> On Jan 28, 10:18am, Oliver Kiddle wrote:
> } The only things I've knowingly left unimplemented is completion for
> } jobs (because compgen is always run in a subshell)
>
> We could do something about this, generically, by saving local copies of
> the jobstates and jobtexts hashes in _main_complete or some such.
I didn't think of that. I've done that in the _bash_completion
function. I can't see that it would be particularly useful to have in
_main_complete (matches added by a compadd running in a subshell are
lost anyway).
It's not likely to be so useful though because job completion is most
useful with builtins for which we have perfectly good zsh completions
already. But it is nice to have for completeness.
I've attached an update patch which does this job stuff, fixes
$COMP_POINT and does complete -r. Only thing it doesn't do now is
complete bash help topics. The second (mime) attachment is the 4.0 back
port.
Any ideas on where in the manual I should mention this function? It
only needs a couple of lines. The User Contributions chapter seems to
cover stuff in the Functions directory. Or would it be better mentioned
in the FAQ?
Oliver
--- Completion/bashcompinit Wed Jan 29 10:28:23 2003
+++ Completion/bashcompinit Wed Jan 29 10:28:23 2003
@@ -6,12 +6,16 @@
local COMP_POINT COMP_CWORD
local -a COMP_WORDS COMPREPLY BASH_VERSINFO
local COMP_LINE="$words"
+ local -A savejobstates savejobtexts
- (( COMP_POINT = ${#${(j. .)words}} + $$#QIPREFIX + $#IPREFIX + $#PREFIX ))
+ (( COMP_POINT = 1 + ${#${(j. .)words[1,CURRENT-1]}} + $#QIPREFIX + $#IPREFIX + $#PREFIX ))
(( COMP_CWORD = CURRENT - 1))
COMP_WORDS=( $words )
BASH_VERSINFO=( 2 05b 0 1 release )
+ savejobstates=( ${(kv)jobstates} )
+ savejobtexts=( ${(kv)jobtexts} )
+
[[ ${argv[${argv[(I)nospace]:-0}-1]} = -o ]] && suf=( -S '' )
matches=( ${(f)"$(compgen $@)"} )
@@ -38,8 +42,8 @@
}
compgen() {
- local opts prefix suffix ret=1 OPTARG OPTIND
- local -a name res results
+ local opts prefix suffix job OPTARG OPTIND ret=1
+ local -a name res results jids
local -A shortopts
emulate -L sh
@@ -93,12 +97,25 @@
setopt kshglob noshglob braceexpand
results+=( "${res[@]}" )
;;
+ job) results+=( "${savejobtexts[@]%% *}" );;
keyword) results+=( "${(k)reswords[@]}" ) ;;
+ running)
+ jids=( "${(@k)savejobstates[(R)running*]}" )
+ for job in "${jids[@]}"; do
+ results+=( ${savejobtexts[$job]%% *} )
+ done
+ ;;
+ stopped)
+ jids=( "${(@k)savejobstates[(R)suspended*]}" )
+ for job in "${jids[@]}"; do
+ results+=( ${savejobtexts[$job]%% *} )
+ done
+ ;;
setopt|shopt) results+=( "${(k)options[@]}" ) ;;
signal) results+=( "SIG${^signals[@]}" ) ;;
user) results+=( "${(k)userdirs[@]}" ) ;;
variable) results+=( "${(k)parameters[@]}" ) ;;
- helptopic|job|running|stopped) ;;
+ helptopic) ;;
esac
;;
F)
@@ -125,8 +142,8 @@
esac
done
- # support for the last, `word' option to compgen. Not particularly valuable
- # and without it zsh matching can do a better job. Comment in if needed.
+ # support for the last, `word' option to compgen. Zsh's matching does a
+ # better job but if you need to, comment this in and use compadd -U
#shift $(( OPTIND - 1 ))
#(( $# )) && results=( "${(M)results[@]:#$1*}" )
@@ -140,11 +157,11 @@
zparseopts -D -a void o: A: G: W: C: F: P: S: X: a b c d e f g j k u v \
p=print r=remove
if [[ -n $print ]]; then
- for cmd print in ${(kv)_comps[(R)_bash*]}; do
- print "complete ${print#* } $cmd"
- done
+ printf 'complete %2$s %1$s\n' "${(@kv)_comps[(R)_bash*]#* }"
elif [[ -n $remove ]]; then
- print "not implemented: -r option"
+ for cmd; do
+ unset "_comps[$cmd]"
+ done
else
compdef _bash_complete\ ${(j. .)${(q)args[1,-1-$#]}} "$@"
fi
This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.
[-- Attachment #2: 4.0 back port --]
[-- Type: text/plain, Size: 5121 bytes --]
--- bashcompinit.new Wed Jan 29 10:28:23 2003
+++ bashcompinit.4.0 Wed Jan 29 10:28:23 2003
@@ -7,6 +7,7 @@
local -a COMP_WORDS COMPREPLY BASH_VERSINFO
local COMP_LINE="$words"
local -A savejobstates savejobtexts
+ set -- $=_bash_comps[$service]
(( COMP_POINT = 1 + ${#${(j. .)words[1,CURRENT-1]}} + $#QIPREFIX + $#IPREFIX + $#PREFIX ))
(( COMP_CWORD = CURRENT - 1))
@@ -59,77 +60,77 @@
[abcdefgjkuv]) OPTARG="${shortopts[$name]}" ;&
A)
case $OPTARG in
- alias) results+=( "${(k)aliases[@]}" ) ;;
- arrayvar) results+=( "${(k@)parameters[(R)array*]}" ) ;;
- binding) results+=( "${(k)widgets[@]}" ) ;;
- builtin) results+=( "${(k)builtins[@]}" "${(k)dis_builtins[@]}" ) ;;
+ alias) results=( "${results[@]}" "${(k)aliases[@]}" ) ;;
+ arrayvar) results=( "${results[@]}" "${(k@)parameters[(R)array*]}" ) ;;
+ binding) results=( "${results[@]}" "${(k)widgets[@]}" ) ;;
+ builtin) results=( "${results[@]}" "${(k)builtins[@]}" "${(k)dis_builtins[@]}" ) ;;
command)
- results+=(
- "${(k)commands[@]}" "${(k)aliases[@]}" "${(k)builtins[@]}"
- "${(k)functions[@]}" "${(k)reswords[@]}"
+ results=(
+ "${results[@]}" "${(k)commands[@]}" "${(k)aliases[@]}"
+ "${(k)builtins[@]}" "${(k)functions[@]}" "${(k)reswords[@]}"
)
;;
directory)
setopt bareglobqual
- results+=( ${IPREFIX}${PREFIX}*${SUFFIX}${ISUFFIX}(N-/) )
+ results=( "${results[@]}" ${IPREFIX}${PREFIX}*${SUFFIX}${ISUFFIX}(N-/) )
setopt nobareglobqual
;;
- disabled) results+=( "${(k)dis_builtins[@]}" ) ;;
- enabled) results+=( "${(k)builtins[@]}" ) ;;
- export) results+=( "${(k)parameters[(R)*export*]}" ) ;;
+ disabled) results=( "${results[@]}" "${(k)dis_builtins[@]}" ) ;;
+ enabled) results=( "${results[@]}" "${(k)builtins[@]}" ) ;;
+ export) results=( "${results[@]}" "${(k)parameters[(R)*export*]}" ) ;;
file)
setopt bareglobqual
- results+=( ${IPREFIX}${PREFIX}*${SUFFIX}${ISUFFIX}(N) )
+ results=( "${results[@]}" ${IPREFIX}${PREFIX}*${SUFFIX}${ISUFFIX}(N) )
setopt nobareglobqual
;;
- function) results+=( "${(k)functions[@]}" ) ;;
+ function) results=( "${results[@]}" "${(k)functions[@]}" ) ;;
group)
emulate zsh
_groups -U -O res
emulate sh
setopt kshglob noshglob braceexpand
- results+=( "${res[@]}" )
+ results=( "${results[@]}" "${res[@]}" )
;;
hostname)
emulate zsh
_hosts -U -O res
emulate sh
setopt kshglob noshglob braceexpand
- results+=( "${res[@]}" )
+ results=( "${results[@]}" "${res[@]}" )
;;
- job) results+=( "${savejobtexts[@]%% *}" );;
- keyword) results+=( "${(k)reswords[@]}" ) ;;
+ job) results=( "${results[@]}" "${savejobtexts[@]%% *}" );;
+ keyword) results=( "${results[@]}" "${(k)reswords[@]}" ) ;;
running)
jids=( "${(@k)savejobstates[(R)running*]}" )
for job in "${jids[@]}"; do
- results+=( ${savejobtexts[$job]%% *} )
+ results=( "${results[@]}" ${savejobtexts[$job]%% *} )
done
;;
stopped)
jids=( "${(@k)savejobstates[(R)suspended*]}" )
for job in "${jids[@]}"; do
- results+=( ${savejobtexts[$job]%% *} )
+ results=( "${results[@]}" ${savejobtexts[$job]%% *} )
done
;;
- setopt|shopt) results+=( "${(k)options[@]}" ) ;;
- signal) results+=( "SIG${^signals[@]}" ) ;;
- user) results+=( "${(k)userdirs[@]}" ) ;;
- variable) results+=( "${(k)parameters[@]}" ) ;;
+ setopt|shopt) results=( "${results[@]}" "${(k)options[@]}" ) ;;
+ signal) results=( "${results[@]}" "SIG${^signals[@]}" ) ;;
+ user) results=( "${results[@]}" "${(k)userdirs[@]}" ) ;;
+ variable) results=( "${results[@]}" "${(k)parameters[@]}" ) ;;
helptopic) ;;
esac
;;
F)
COMPREPLY=()
$OPTARG "${words[0]}" "${words[CURRENT-1]}" "${words[CURRENT-2]}"
- results+=( "${COMPREPLY[@]}" )
+ results=( "${results[@]}" "${COMPREPLY[@]}" )
;;
G)
setopt nullglob
- results+=( ${~OPTARG} )
+ results=( "${results[@]}" ${~OPTARG} )
unsetopt nullglob
;;
- W) eval "results+=( $OPTARG )" ;;
- C) results+=( $(eval $OPTARG) ) ;;
+ W) eval "results=( "${results[@]}" $OPTARG )" ;;
+ C) results=( "${results[@]}" $(eval $OPTARG) ) ;;
P) prefix="$OPTARG" ;;
S) suffix="$OPTARG" ;;
X)
@@ -157,16 +158,22 @@
zparseopts -D -a void o: A: G: W: C: F: P: S: X: a b c d e f g j k u v \
p=print r=remove
if [[ -n $print ]]; then
- printf 'complete %2$s %1$s\n' "${(@kv)_comps[(R)_bash*]#* }"
+ for cmd in ${(k)_bash_comps}; do
+ print "complete ${_bash_comps[$cmd]} $cmd"
+ done
elif [[ -n $remove ]]; then
for cmd; do
- unset "_comps[$cmd]"
+ unset "_bash_comps[$cmd]"
done
else
- compdef _bash_complete\ ${(j. .)${(q)args[1,-1-$#]}} "$@"
+ for cmd; do
+ _bash_comps[$cmd]="${args[1,-1-$#]}"
+ done
+ compdef _bash_complete "$@"
fi
}
+typeset -gA _bash_comps
unfunction bashcompinit
autoload -U bashcompinit
return 0
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: bash completion functions
2003-01-29 10:17 ` Oliver Kiddle
@ 2003-01-29 11:16 ` Peter Stephenson
2003-01-29 11:26 ` Peter Stephenson
2003-01-29 14:11 ` Oliver Kiddle
0 siblings, 2 replies; 8+ messages in thread
From: Peter Stephenson @ 2003-01-29 11:16 UTC (permalink / raw)
To: Zsh workers
Oliver Kiddle wrote:
> Any ideas on where in the manual I should mention this function? It
> only needs a couple of lines. The User Contributions chapter seems to
> cover stuff in the Functions directory. Or would it be better mentioned
> in the FAQ?
The reset of the completion system is all in the zshcompsys manual page.
I would either add a new section for odds and ends, or sneak it into the
section `Control Functions'.
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK Tel: +44 (0)1223 692070
**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential
and/or privileged material.
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by
persons or entities other than the intended recipient is
prohibited.
If you received this in error, please contact the sender and
delete the material from any computer.
**********************************************************************
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: bash completion functions
2003-01-29 11:16 ` Peter Stephenson
@ 2003-01-29 11:26 ` Peter Stephenson
2003-01-29 14:11 ` Oliver Kiddle
1 sibling, 0 replies; 8+ messages in thread
From: Peter Stephenson @ 2003-01-29 11:26 UTC (permalink / raw)
To: Zsh workers
Peter Stephenson wrote:
> The reset of the completion system is all in the zshcompsys manual page.
^^^^^ that should say `rest'.
> I would either add a new section for odds and ends, or sneak it into the
> section `Control Functions'.
pws
**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential
and/or privileged material.
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by
persons or entities other than the intended recipient is
prohibited.
If you received this in error, please contact the sender and
delete the material from any computer.
**********************************************************************
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: bash completion functions
2003-01-29 11:16 ` Peter Stephenson
2003-01-29 11:26 ` Peter Stephenson
@ 2003-01-29 14:11 ` Oliver Kiddle
1 sibling, 0 replies; 8+ messages in thread
From: Oliver Kiddle @ 2003-01-29 14:11 UTC (permalink / raw)
To: Zsh workers
On 29 Jan, Peter wrote:
> Oliver Kiddle wrote:
> > Any ideas on where in the manual I should mention this function? It
> > only needs a couple of lines. The User Contributions chapter seems to
> > cover stuff in the Functions directory. Or would it be better mentioned
> > in the FAQ?
>
> The reset of the completion system is all in the zshcompsys manual page.
> I would either add a new section for odds and ends, or sneak it into the
> section `Control Functions'.
I've put it at the end of Control Functions which results in it being
just before _bash_completions in the Bindable Commands section.
The patch below also adds documentation for the styles used by
_email_addresses and changes _email_addresses to use the more
conventional reply array instead of ali for plugins (which I forgot to
do before).
Oliver
Index: Completion/Unix/Type/_email_addresses
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_email_addresses,v
retrieving revision 1.1
diff -u -r1.1 _email_addresses
--- Completion/Unix/Type/_email_addresses 17 Jan 2003 09:23:35 -0000 1.1
+++ Completion/Unix/Type/_email_addresses 29 Jan 2003 13:57:33 -0000
@@ -7,14 +7,14 @@
#
# Plugins are written as separate functions with names starting `_email-'.
# They should either do their own completion or return the addresses in the
-# ali array in the form 'alias:address' and return 300. The -c option is
+# reply array in the form 'alias:address' and return 300. The -c option is
# passed on to plugins (and -n could be if needed ever). New plugins will be
# picked up and run automatically.
# plugins
(( $+functions[_email-mail] )) ||
_email-mail() {
- ali=( ${${${(M)${(f)"$(<$files[$plugin])"}:#alias*}##alias[[:blank:]]##}/[[:blank:]]##/:} )
+ reply=( ${${${(M)${(f)"$(<$files[$plugin])"}:#alias*}##alias[[:blank:]]##}/[[:blank:]]##/:} )
return 300
}
(( $+functions[_email-mutt] )) || _email-mutt() { _email-mail }
@@ -22,13 +22,13 @@
(( $+functions[_email-MH] )) ||
_email-MH() {
- ali=( ${${(f)"$(_call_program aliases ali)"}/: /:} )
+ reply=( ${${(f)"$(_call_program aliases ali)"}/: /:} )
return 300
}
(( $+functions[_email-pine] )) ||
_email-pine() {
- ali=( ${${${${${(f)"$(<~/.addressbook)"}:#*DELETED*}:#\ *}/ [^ ]# /:}%% *} )
+ reply=( ${${${${${(f)"$(<~/.addressbook)"}:#*DELETED*}:#\ *}/ [^ ]# /:}%% *} )
return 300
}
@@ -77,7 +77,7 @@
}
_email_addresses() {
- local -a plugins ali list args
+ local -a plugins reply list args
local -A opts files
local plugin rcfile expl ret fret
@@ -147,17 +147,17 @@
if (( fret == 300 )); then
if (( ! $+opts[-c] )) && [[ $opts[-n] = $plugin ]]; then
- zformat -a list ' -- ' "${ali[@]}"
+ zformat -a list ' -- ' "${reply[@]}"
_wanted mail-aliases expl 'alias' compadd "$@" \
- -d list - ${ali%%:*} && ret=0
+ -d list - ${reply%%:*} && ret=0
else
if (( $#args )); then
- ali=( ${(SM)${ali#*:}##$~__addrspec} )
+ reply=( ${(SM)${reply#*:}##$~__addrspec} )
else
# remove lines not containing `@' as they probably aren't addresses
- ali=( "${(@)${(M@)ali:#*@*}#*:}" )
+ reply=( "${(@)${(M@)reply:#*@*}#*:}" )
fi
- compadd -a "$@" "$expl[@]" ali && ret=0
+ compadd -a "$@" "$expl[@]" reply && ret=0
fi
fi
done
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.162
diff -u -r1.162 compsys.yo
--- Doc/Zsh/compsys.yo 27 Jan 2003 16:42:27 -0000 1.162
+++ Doc/Zsh/compsys.yo 29 Jan 2003 13:57:33 -0000
@@ -1244,6 +1244,15 @@
sorted alphabetically by name. If the value contains the string
`tt(reverse)', sorting is done in decreasing order.
)
+kindex(filter, completion style)
+item(tt(filter))(
+This is used by the LDAP plugin for e-mail address completion to specify
+the attributes to match against when filtering entries. So for example, if
+the style is set to `tt(sn)', matching is done against surnames. Standard
+LDAP filtering is used so normal completion matching is bypassed. If this
+style is not set, the LDAP plugin is skipped. You may also need to set the
+tt(command) style before it can connect to your LDAP server though.
+)
kindex(force-list, completion style)
item(tt(force-list))(
This forces a list of completions to be shown at any point where listing is
@@ -2091,6 +2100,13 @@
default), tt(_history_complete_word) will loop immediately as in a
menu completion.
)
+kindex(strip-comments, completion style)
+item(tt(strip-comments))(
+If set to `true', this style causes non-essential comment text to be
+removed from the completion matches. Currently it is only used when
+completing e-mail addresses where it removes any display name from the
+addresses, cutting them down to plain var(user@host) form.
+)
kindex(subst-globs-only, completion style)
item(tt(subst-globs-only))(
This is used by the tt(_expand) completer. If it is set to `true',
@@ -2855,6 +2871,14 @@
tt(COMPLETE_IN_WORD) option is set; otherwise, the cursor will
be moved to the end of the current word before the completion code is
called and hence there will be no suffix.
+)
+findex(bashcompinit)
+item(tt(bashcompinit))(
+This function provides compatibility with bash's programmable completion
+system. When run it will define the functions, tt(compgen) and
+tt(complete) which correspond to the bash builtins with the same names. It
+will then be possible to use completion specifications and functions
+written for bash.
)
enditem()
This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: bash completion functions
2003-01-28 9:18 bash completion functions Oliver Kiddle
2003-01-28 9:25 ` Zefram
2003-01-28 16:42 ` Bart Schaefer
@ 2003-02-03 12:51 ` Clemens Fischer
2 siblings, 0 replies; 8+ messages in thread
From: Clemens Fischer @ 2003-02-03 12:51 UTC (permalink / raw)
To: zsh-workers
Oliver Kiddle <okiddle@yahoo.co.uk>:
> _bash_complete() {
> local ret=1
> local -a suf matches
> local COMP_POINT COMP_CWORD
> local -a COMP_WORDS COMPREPLY BASH_VERSINFO
> local COMP_LINE="$words"
>
> (( COMP_POINT = ${#${(j. .)words}} + $$#QIPREFIX + $#IPREFIX + $#PREFIX ))
> (( COMP_CWORD = CURRENT - 1))
> COMP_WORDS=( $words )
> BASH_VERSINFO=( 2 05b 0 1 release )
>
> [[ ${argv[${argv[(I)nospace]:-0}-1]} = -o ]] && suf=( -S '' )
> [...]
this is nice. i learn much more about zsh mechanics now that i can
compare known functions with their zsh equivalent!
one thing, though: you provide this patch, a patch to it and another
one on top of the last. would you please post the complete version,
all goodies included?
clemens
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2003-02-03 13:12 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-28 9:18 bash completion functions Oliver Kiddle
2003-01-28 9:25 ` Zefram
2003-01-28 16:42 ` Bart Schaefer
2003-01-29 10:17 ` Oliver Kiddle
2003-01-29 11:16 ` Peter Stephenson
2003-01-29 11:26 ` Peter Stephenson
2003-01-29 14:11 ` Oliver Kiddle
2003-02-03 12:51 ` Clemens Fischer
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).