* Brace expansion vs. TAB
@ 2019-12-06 17:18 Dominik Vogt
2019-12-07 10:05 ` Mikael Magnusson
0 siblings, 1 reply; 6+ messages in thread
From: Dominik Vogt @ 2019-12-06 17:18 UTC (permalink / raw)
To: Zsh Users
(Using zsh 5.3.1 on Debian.)
In a directory with c++ sources:
$ ls *
foo.cpp foo.h
Now,
$ grep ... *.{hpp,cpp}<TAB>
results in
$ grep ... foo.cpp
But
$ grep ... *.{hpp,cpp}<ENTER>
zsh: no matches found: *.hpp
--
Q1:
Well, that is probably because Tab expansion is totally different
from filename generation and the NOMATH option is enabled (by
default?). But is there a way to get rid of the error message in
this specific case only? I.e. to disable the NOMATCH option in
command using brace expansion only?
Q2:
What I really want to have is a simple way to get all c and c++
filenames in a singel pattern, like
$ grep ... *.{h,c,hpp,cpp,hxx,cxx}
$ grep ... **/*.{h,c,hpp,cpp,hxx,cxx}
In an ideal world I'd like to have something very simple that
worked with c sources, but not with c++.
$ grep ... **/*.[ch]
->
$ alias -g CH="{h,c,hpp,cpp,hxx,cxx}"
$ grep ... **/*.CH
(Yeah, I know global aliases dont't work this way.)
Ciao
Dominik ^_^ ^_^
--
Dominik Vogt
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Brace expansion vs. TAB
2019-12-06 17:18 Brace expansion vs. TAB Dominik Vogt
@ 2019-12-07 10:05 ` Mikael Magnusson
2019-12-07 12:32 ` Dominik Vogt
0 siblings, 1 reply; 6+ messages in thread
From: Mikael Magnusson @ 2019-12-07 10:05 UTC (permalink / raw)
To: dominik.vogt, Zsh Users
On 12/6/19, Dominik Vogt <dominik.vogt@gmx.de> wrote:
> (Using zsh 5.3.1 on Debian.)
>
> In a directory with c++ sources:
>
> $ ls *
> foo.cpp foo.h
>
> Now,
>
> $ grep ... *.{hpp,cpp}<TAB>
>
> Q2:
>
> What I really want to have is a simple way to get all c and c++
> filenames in a singel pattern, like
*.(hpp|cpp) or for that matter, *.[hc]pp
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Brace expansion vs. TAB
2019-12-07 10:05 ` Mikael Magnusson
@ 2019-12-07 12:32 ` Dominik Vogt
2019-12-07 13:23 ` Re[2]: " Manuel Presnitz
0 siblings, 1 reply; 6+ messages in thread
From: Dominik Vogt @ 2019-12-07 12:32 UTC (permalink / raw)
To: Zsh Users
On Sat, Dec 07, 2019 at 11:05:01AM +0100, Mikael Magnusson wrote:
> On 12/6/19, Dominik Vogt <dominik.vogt@gmx.de> wrote:
> > (Using zsh 5.3.1 on Debian.)
> >
> > In a directory with c++ sources:
> >
> > $ ls *
> > foo.cpp foo.h
> >
> > Now,
> >
> > $ grep ... *.{hpp,cpp}<TAB>
> >
> > Q2:
> >
> > What I really want to have is a simple way to get all c and c++
> > filenames in a singel pattern, like
>
> *.(hpp|cpp)
Ah, thanks. This works:
alias -g CH="*.(c|h|cpp|hpp|cxx|hxx)"
alias -g CHR="**/*.(c|h|cpp|hpp|cxx|hxx)"
grep foo CHR
grep bar CH
> or for that matter, *.[hc]pp
Nope. Doesn't match header files wit .h suffix.
Ciao
Dominik ^_^ ^_^
--
Dominik Vogt
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re[2]: Brace expansion vs. TAB
2019-12-07 12:32 ` Dominik Vogt
@ 2019-12-07 13:23 ` Manuel Presnitz
2019-12-07 13:33 ` Dominik Vogt
0 siblings, 1 reply; 6+ messages in thread
From: Manuel Presnitz @ 2019-12-07 13:23 UTC (permalink / raw)
To: dominik.vogt, Zsh Users
> > *.(hpp|cpp)
> (...)
> > or for that matter, *.[hc]pp
>
> Nope. Doesn't match header files wit .h suffix.
You can combine both suggestions to
*.[hc](|pp|xx)
which is a little bit shorter than *.(c|h|cpp|hpp|cxx|hxx)
Manuel.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Brace expansion vs. TAB
2019-12-07 13:23 ` Re[2]: " Manuel Presnitz
@ 2019-12-07 13:33 ` Dominik Vogt
2019-12-08 1:23 ` Daniel Shahaf
0 siblings, 1 reply; 6+ messages in thread
From: Dominik Vogt @ 2019-12-07 13:33 UTC (permalink / raw)
To: Zsh Users
On Sat, Dec 07, 2019 at 02:23:53PM +0100, Manuel Presnitz wrote:
> > > *.(hpp|cpp)
> > (...)
> > > or for that matter, *.[hc]pp
> >
> > Nope. Doesn't match header files wit .h suffix.
>
> You can combine both suggestions to
>
> *.[hc](|pp|xx)
>
> which is a little bit shorter than *.(c|h|cpp|hpp|cxx|hxx)
Okay, but what I'm really missing no are global aliases that match
*parts* of words, so that
alias -g '*.CH'='*.[ch](|xx|pp)'
$ grep foo **/*.CH
works. Or some way to preprocess the command line with a sed
script.
Ciao
Dominik ^_^ ^_^
--
Dominik Vogt
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Brace expansion vs. TAB
2019-12-07 13:33 ` Dominik Vogt
@ 2019-12-08 1:23 ` Daniel Shahaf
0 siblings, 0 replies; 6+ messages in thread
From: Daniel Shahaf @ 2019-12-08 1:23 UTC (permalink / raw)
To: Dominik Vogt, Zsh Users
Dominik Vogt wrote on Sat, 07 Dec 2019 13:33 +00:00:
> alias -g '*.CH'='*.[ch](|xx|pp)'
> $ grep foo **/*.CH
# apt install the-silver-searcher
% ag --cc foo
% ag --cpp foo
> Or some way to preprocess the command line with a sed
> script.
You can certainly do that with widgets: just pass ${BUFFER} through sed.
If you want syntax awareness, do buf="$PREBUFFER$BUFFER" then look into
${(z)buf}. Don't forget to also use ${(Z)} if needed (z-sy-h has examples).
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-12-08 1:25 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-06 17:18 Brace expansion vs. TAB Dominik Vogt
2019-12-07 10:05 ` Mikael Magnusson
2019-12-07 12:32 ` Dominik Vogt
2019-12-07 13:23 ` Re[2]: " Manuel Presnitz
2019-12-07 13:33 ` Dominik Vogt
2019-12-08 1:23 ` Daniel Shahaf
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).