Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: completions issues



В Чтв, 11.07.2002, в 00:47, GoTaR написал:
> Hi!
> 
> I've got some problems with creating my own rule for sms sending
> program. Here comes the significant part:
> 
> _sms_aliases () {
> 	compadd "$@" $(print ${(f)"$(smsaddr -l | cut -f1)"})
> }
> [...]
> 		_arguments -C \
>                         '-r[remove existing entry]:SMS alias:_sms_aliases'
> 
> smsaddr returns two columns, completion should be done from both, but
> treated as one entry, e. g.:
> 
> $ smsaddr -l
> alias1		608612341
> alias2		504147432
> blias3		603648734
> 
> $ smsaddr -r a[tab]... lias2
> alias1          608612341
> alias2          504147432
> 
> $ smsaddr -r 6[tab]... 08612341
> alias1          608612341
> blias3          603648734
> 
> so one column will be used as comment.
> 
> I will be very grateful for help.
> 

_sms_aliases should check both fields and add the first if any matches.
To prevent completion using own matching use -U flag to compadd.
Something like

ret=1
smsaddr -l  | while read alias number; do
  if [[ $alias == $PREFIX*$SUFFIX || $number == $PREFIX*$SUFFIX ]]; then
     compadd -U -- $alias
     ret=0
   fi
done

return $ret

with obvious error checking. If you want to add numbers as descriptions,
somebody else better explains how to do it :-) 

-andrej



Messages sorted by: Reverse Date, Date, Thread, Author