* String partial match from both left and right. @ 2018-08-31 10:24 ` Abhijeet Rastogi 2018-08-31 11:01 ` Peter Stephenson 2018-08-31 11:11 ` Oliver Kiddle 0 siblings, 2 replies; 4+ messages in thread From: Abhijeet Rastogi @ 2018-08-31 10:24 UTC (permalink / raw) To: zsh-workers [-- Attachment #1: Type: text/plain, Size: 630 bytes --] Hi everyone, I have this super simple zsh completion function. function hello() { arg=${@[1]} echo $arg } function _hello { _values -s ' ' 'dashboards' foo bar foo-bar } compdef _hello hello And what I want is, if I do:- $hello bar<TAB> I want `foo-bar` to come in the completion menu. I figured that it has something to do with mater-list but I can't seem to get it working. zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'l:|=* r:|=*' Let me know if you guys need any more debugging info. I've been scratching my head on this one but can't get it to work. -- Cheers, Abhijeet Rastogi (shadyabhi) ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: String partial match from both left and right. 2018-08-31 10:24 ` String partial match from both left and right Abhijeet Rastogi @ 2018-08-31 11:01 ` Peter Stephenson 2018-08-31 11:11 ` Oliver Kiddle 1 sibling, 0 replies; 4+ messages in thread From: Peter Stephenson @ 2018-08-31 11:01 UTC (permalink / raw) To: Abhijeet Rastogi, zsh-workers On Fri, 31 Aug 2018 15:54:02 +0530 Abhijeet Rastogi <abhijeet.1989@gmail.com> wrote: > Hi everyone, > > I have this super simple zsh completion function. > > function hello() { > arg=${@[1]} > echo $arg > } > function _hello { > _values -s ' ' 'dashboards' foo bar foo-bar > } > compdef _hello hello > > And what I want is, if I do:- > > $hello bar<TAB> > > I want `foo-bar` to come in the completion menu. I figured that it has > something to do with mater-list but I can't seem to get it working. > > zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'l:|=* > r:|=*' (This should really got to zsh-users as it's not about implementation.) Best I could come up with quickly was zstyle ':completion:*:hello:*' matcher-list 'r:|-*' where it works if you type "-b", i.e. you need the hyphen but not anything before it. pws ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: String partial match from both left and right. 2018-08-31 10:24 ` String partial match from both left and right Abhijeet Rastogi 2018-08-31 11:01 ` Peter Stephenson @ 2018-08-31 11:11 ` Oliver Kiddle 2018-09-02 4:37 ` Abhijeet Rastogi 1 sibling, 1 reply; 4+ messages in thread From: Oliver Kiddle @ 2018-08-31 11:11 UTC (permalink / raw) To: Abhijeet Rastogi; +Cc: zsh-workers Abhijeet Rastogi wrote: > function _hello { > _values -s ' ' 'dashboards' foo bar foo-bar > } > compdef _hello hello > > And what I want is, if I do:- > > $hello bar<TAB> > > I want `foo-bar` to come in the completion menu. I figured that it has > something to do with mater-list but I can't seem to get it working. You're right that the matching control is the way to achieve this and in particular the 'l:|=*' specification. > zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'l:|=* r:|=*' That sets a global matcher to apply for all completions. It will first try case-insensitive matching and then try again with extra characters allowed at both the beginning (left) and end (right) of what has been typed. When you complete bar<tab>, the "bar" candidate will match when doing the initial case-insensitive match and is accepted. It then never gets to try the second matching rule. You need the l: spec in the first argument so it would work with either: zstyle ':completion:*' matcher-list 'l:|=*' or: zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z} l:|=* r:|=*' That assumes you don't have any other matcher-list styles with a more specific context. Also, as I mentioned setting matcher-list is a fairly global setting. If you only want this for hello then the matcher style might be more appropriate: zstyle ':completion:*:hello:values:*' matcher 'l:|=*' Alternatively you might want to specify the matcher directly in the _hello function. For example: function _hello { _wanted dashboards expl 'dashboard' compadd -M 'l:|=*' foo bar foo-bar } There are other things you might try, for example r:|-=* allows f-b to match foo-bar. Oliver ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: String partial match from both left and right. 2018-08-31 11:11 ` Oliver Kiddle @ 2018-09-02 4:37 ` Abhijeet Rastogi 0 siblings, 0 replies; 4+ messages in thread From: Abhijeet Rastogi @ 2018-09-02 4:37 UTC (permalink / raw) To: okiddle; +Cc: zsh-workers [-- Attachment #1: Type: text/plain, Size: 2045 bytes --] Hi, Thanks, Peter. And special thanks to Oliver for the excellent explanation so I could up on what you gave me. I ended up using your approach. On Fri, Aug 31, 2018 at 4:41 PM Oliver Kiddle <okiddle@yahoo.co.uk> wrote: > Abhijeet Rastogi wrote: > > function _hello { > > _values -s ' ' 'dashboards' foo bar foo-bar > > } > > compdef _hello hello > > > > And what I want is, if I do:- > > > > $hello bar<TAB> > > > > I want `foo-bar` to come in the completion menu. I figured that it has > > something to do with mater-list but I can't seem to get it working. > > You're right that the matching control is the way to achieve this and in > particular the 'l:|=*' specification. > > > zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'l:|=* r:|=*' > > That sets a global matcher to apply for all completions. It will first > try case-insensitive matching and then try again with extra characters > allowed at both the beginning (left) and end (right) of what has been > typed. When you complete bar<tab>, the "bar" candidate will match when > doing the initial case-insensitive match and is accepted. It then never > gets to try the second matching rule. > > You need the l: spec in the first argument so it would work with either: > zstyle ':completion:*' matcher-list 'l:|=*' > or: > zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z} l:|=* r:|=*' > > That assumes you don't have any other matcher-list styles with a more > specific context. > > Also, as I mentioned setting matcher-list is a fairly global setting. If > you only want this for hello then the matcher style might be more > appropriate: > zstyle ':completion:*:hello:values:*' matcher 'l:|=*' > > Alternatively you might want to specify the matcher directly in the > _hello function. For example: > > function _hello { > _wanted dashboards expl 'dashboard' compadd -M 'l:|=*' foo bar foo-bar > } > > There are other things you might try, for example r:|-=* allows f-b to > match foo-bar. > > Oliver > -- Cheers, Abhijeet Rastogi (shadyabhi) ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-09-02 4:40 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <CGME20180831102508epcas4p4e1fdd60db2ae6336248268c887908f23@epcas4p4.samsung.com> 2018-08-31 10:24 ` String partial match from both left and right Abhijeet Rastogi 2018-08-31 11:01 ` Peter Stephenson 2018-08-31 11:11 ` Oliver Kiddle 2018-09-02 4:37 ` Abhijeet Rastogi
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).