zsh-users
 help / color / mirror / code / Atom feed
* completions issues
@ 2002-07-10 20:47 GoTaR
  2002-07-12 18:44 ` Borsenkow Andrej
  0 siblings, 1 reply; 8+ messages in thread
From: GoTaR @ 2002-07-10 20:47 UTC (permalink / raw)
  To: zsh-users

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.

-- 
GoTaR <gotar@priv0.onet.pl>
PLD stuff at http://mops.uci.agh.edu.pl/~gotar/


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: completions issues
  2002-07-10 20:47 completions issues GoTaR
@ 2002-07-12 18:44 ` Borsenkow Andrej
  2002-07-13 19:37   ` GoTaR
  0 siblings, 1 reply; 8+ messages in thread
From: Borsenkow Andrej @ 2002-07-12 18:44 UTC (permalink / raw)
  To: GoTaR; +Cc: zsh-users

В Чтв, 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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: completions issues
  2002-07-12 18:44 ` Borsenkow Andrej
@ 2002-07-13 19:37   ` GoTaR
  2002-07-13 21:20     ` Bart Schaefer
  2002-07-14  8:57     ` Borsenkow Andrej
  0 siblings, 2 replies; 8+ messages in thread
From: GoTaR @ 2002-07-13 19:37 UTC (permalink / raw)
  To: Borsenkow Andrej; +Cc: zsh-users

On Fri, Jul 12, 2002 at 22:44:56 +0400, Borsenkow Andrej wrote:

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

Ok, I've done this this way, perl rox;)

_sms_aliases () {
        smsas=(`smsaddr -l | perl -ne 's/		/:/; if
(/^'$PREFIX'/) {print} else {if (/:'$PREFIX'/) {/^(.*):(.*)$/; print
"$2:$1\n"}}'`)
        _describe "SMS alias" "smsas"
}

gotar:~: smsaddr -l [tab]
SMS alias
6bone    -- 509xxx
admol    -- 602xxx
joanne   -- 604xxx
prudy    -- 600xxx
rtrzepla -- 692xxx
rzuku    -- 609xxx

gotar:~: smsaddr -l r[tab]
SMS alias
rtrzepla -- 692xxx
rzuku    -- 609xxx

gotar:~: smsaddr -l 6[tab]
SMS alias
600xxx -- prudy
602xxx -- admol
604xxx -- joanne
609xxx -- rzuku
692xxx -- rtrzepla
6bone  -- 509xxx

And question: how to make it without perl?

BTW:

_arguments \
	'*-sub[subtitles]:subtitles:_files -/ -g \*.\(\#i\)txt' \
	'*:multimedia file:_files -/ -g \*.\(\#i\)\(mp3\|mpg\)'

$ command [tab]
multimedia file
News/   OpenOffice.org1.0/

$ command -sub [tab]
subtitles
News/   OpenOffice.org1.0/

BUT:

$ command a1.mpg -sub [tab]
subtitles
News/   OpenOffice.org1.0/
multimedia file
News/   OpenOffice.org1.0/

Why there are these TWO completions?

Thanks!

-- 
GoTaR <gotar@priv0.onet.pl>
PLD stuff at http://mops.uci.agh.edu.pl/~gotar/


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: completions issues
  2002-07-13 19:37   ` GoTaR
@ 2002-07-13 21:20     ` Bart Schaefer
  2002-07-14 10:55       ` GoTaR
  2002-07-14  8:57     ` Borsenkow Andrej
  1 sibling, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2002-07-13 21:20 UTC (permalink / raw)
  To: GoTaR; +Cc: zsh-users

On Jul 13,  9:37pm, GoTaR wrote:
} Subject: Re: completions issues
}
} _sms_aliases () {
}         smsas=(`smsaddr -l | perl -ne 's/		/:/; if
} (/^'$PREFIX'/) {print} else {if (/:'$PREFIX'/) {/^(.*):(.*)$/; print
} "$2:$1\n"}}'`)
}         _describe "SMS alias" "smsas"
} }
} 
} And question: how to make it without perl?

  _sms_aliases () {
    smsas=( ${(f)$(smsaddr -l)} )
    smsas=( ${smsas/		/:}
	    ${smsas/(#s)(#b)(*)		(*)(#e)/$match[2]:$match[1]} )
    smsas=( ${(M)smsas:#$PREFIX*} )
    _describe "SMS alias" smsas
  }

I don't think you even need that last smsas= that matches against $PREFIX,
as the completion internals should take care of filtering the possible
matches generated by _sms_aliases against the actual input on the line.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: completions issues
  2002-07-13 19:37   ` GoTaR
  2002-07-13 21:20     ` Bart Schaefer
@ 2002-07-14  8:57     ` Borsenkow Andrej
  2002-07-14 10:49       ` GoTaR
  1 sibling, 1 reply; 8+ messages in thread
From: Borsenkow Andrej @ 2002-07-14  8:57 UTC (permalink / raw)
  To: GoTaR; +Cc: zsh-users

В Сбт, 13.07.2002, в 23:37, GoTaR написал:
> On Fri, Jul 12, 2002 at 22:44:56 +0400, Borsenkow Andrej wrote:
> 
> > with obvious error checking. If you want to add numbers as descriptions,
> > somebody else better explains how to do it :-) 
> 
> Ok, I've done this this way, perl rox;)
> 
> _sms_aliases () {
>         smsas=(`smsaddr -l | perl -ne 's/		/:/; if
> (/^'$PREFIX'/) {print} else {if (/:'$PREFIX'/) {/^(.*):(.*)$/; print
> "$2:$1\n"}}'`)
>         _describe "SMS alias" "smsas"
> }
> 
[...]
> gotar:~: smsaddr -l r[tab]
> SMS alias
> rtrzepla -- 692xxx
> rzuku    -- 609xxx
> 
> gotar:~: smsaddr -l 6[tab]
> SMS alias
> 600xxx -- prudy
> 602xxx -- admol


Oh, if you want _this_ you do not need any perl magic at all. Just add
all your SMS aliases two times - once as alias:number and second time as
number:alias. Completion does all matching for you.

I assumed you always to always have alias name as match and number as
description. Here you should do matching yourself. But not in above case
when completion does it for you.

-andrej


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: completions issues
  2002-07-14  8:57     ` Borsenkow Andrej
@ 2002-07-14 10:49       ` GoTaR
  0 siblings, 0 replies; 8+ messages in thread
From: GoTaR @ 2002-07-14 10:49 UTC (permalink / raw)
  To: Borsenkow Andrej; +Cc: zsh-users

On Sun, Jul 14, 2002 at 12:57:10 +0400, Borsenkow Andrej wrote:

> > gotar:~: smsaddr -l r[tab]
> > SMS alias
> > rtrzepla -- 692xxx
> > 
> > gotar:~: smsaddr -l 6[tab]
> > SMS alias
> > 600xxx -- prudy
> 
> Oh, if you want _this_ you do not need any perl magic at all. Just add
> all your SMS aliases two times - once as alias:number and second time as
> number:alias. Completion does all matching for you.

No no no, adding both will cause showing them _all_ when completion
without any prefix - and I don't want doubled entries like this:

gotar:~: smsaddr -l [tab]
SMS alias
rtrzepla -- 692xxx
692xxx   -- rtrzepla

> I assumed you always to always have alias name as match and number as
> description.

No, it should be dynamically switched for every entry separately, e. g.

gotar:~: smsaddr -l [tab]
SMS alias
6bone    -- 509xxx
admol    -- 602xxx

gotar:~: smsaddr -l 6[tab]
SMS alias
602xxx -- admol
6bone  -- 509xxx

As you can see here - 6 is used as prefix to alias OR number and part
without it is used as description.

-- 
GoTaR <gotar@priv0.onet.pl>
PLD stuff at http://mops.uci.agh.edu.pl/~gotar/


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: completions issues
  2002-07-13 21:20     ` Bart Schaefer
@ 2002-07-14 10:55       ` GoTaR
  2002-07-14 21:09         ` Bart Schaefer
  0 siblings, 1 reply; 8+ messages in thread
From: GoTaR @ 2002-07-14 10:55 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

On Sat, Jul 13, 2002 at 21:20:37 +0000, Bart Schaefer wrote:

> } And question: how to make it without perl?
> 
>     smsas=( ${(f)$(smsaddr -l)} )

Here is the first trap - ${(f)... will change double tab to space, so
smsas would contain 'alias number alias number...' instead of
'alias<tab><tab>number alias<tab><tab>number...'...

>     smsas=( ${smsas/		/:}

...and this won't work.

> 	    ${smsas/(#s)(#b)(*)		(*)(#e)/$match[2]:$match[1]} )
>     smsas=( ${(M)smsas:#$PREFIX*} )
> 
> I don't think you even need that last smsas= that matches against $PREFIX,
> as the completion internals should take care of filtering the possible
> matches generated by _sms_aliases against the actual input on the line.

Completion filters possibilities by matchers, not their descriptions. In
my case matcher and description must be dynamically chosen on the
strength of prefix. As in other post:

gotar:~: smsaddr -l [tab]
SMS alias
6bone    -- 509xxx
admol    -- 602xxx

here admol is to be completed, 602xxx is description, but in:

gotar:~: smsaddr -l 6[tab]
SMS alias
6bone    -- 509xxx
602xxx   -- admol

602xxx is to be completed (prefix '6') and admol is it's description.

-- 
GoTaR <gotar@priv0.onet.pl>
PLD stuff at http://mops.uci.agh.edu.pl/~gotar/


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: completions issues
  2002-07-14 10:55       ` GoTaR
@ 2002-07-14 21:09         ` Bart Schaefer
  0 siblings, 0 replies; 8+ messages in thread
From: Bart Schaefer @ 2002-07-14 21:09 UTC (permalink / raw)
  To: GoTaR; +Cc: zsh-users

On Jul 14, 12:55pm, GoTaR wrote:
} Subject: Re: completions issues
}
} On Sat, Jul 13, 2002 at 21:20:37 +0000, Bart Schaefer wrote:
} 
} > } And question: how to make it without perl?
} > 
} >     smsas=( ${(f)$(smsaddr -l)} )
} 
} Here is the first trap - ${(f)... will change double tab to space

That has nothing to do with ${(f)...}.  It's just that I lost the double
quotes somehow when typing my reply:

	smsas=( ${(f)"$(smsaddr -l)"} )

Elsewhere, you wrote:

} No no no, adding both will cause showing them _all_ when completion
} without any prefix - and I don't want doubled entries like this:
} 
} gotar:~: smsaddr -l [tab]
} SMS alias
} rtrzepla -- 692xxx
} 692xxx   -- rtrzepla

Getting a little demanding, aren't we?

Anyway, just add the inverted pairs only when the word on the line is
non-empty, and then let completion deal with it from there.

  _sms_aliases () {
    smsas=( ${(f)"$(smsaddr -l)"} )
    smsas=( ${smsas/		/:} )
    if [[ -n "$PREFIX$SUFFIX" ]]; then
      smsas=( ${smsas/(#s)(#b)(*)		(*)(#e)/$match[2]:$match[1]} )
    fi
    _describe "SMS alias" smsas
  }


-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2002-07-14 21:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-10 20:47 completions issues GoTaR
2002-07-12 18:44 ` Borsenkow Andrej
2002-07-13 19:37   ` GoTaR
2002-07-13 21:20     ` Bart Schaefer
2002-07-14 10:55       ` GoTaR
2002-07-14 21:09         ` Bart Schaefer
2002-07-14  8:57     ` Borsenkow Andrej
2002-07-14 10:49       ` GoTaR

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).