ack . doesn't match but ack * does?

5 views
Skip to first unread message

Brian L. Matthews

unread,
Jul 31, 2023, 4:40:03 PM7/31/23
to ack-...@googlegroups.com
Can someone explain this:

$ ack -l -r --nopager checkboxClass .
$ ack -l -r --nopager checkboxClass *
jquery.uniform.min.js
$ grep -l -r checkboxClass .
./jquery.uniform.min.js
$ grep -l -r checkboxClass *
jquery.uniform.min.js

Why is checkboxClass not found in the first instance? The same things
happens in ancestor directories if I include enough */ before the *. The
directory the file is in doesn't seem unusual, it just has 32 files in
it. Nothing is a symlink. The line checkboxClass is found on is pretty
long, but searching * finds it so I don't think that's related. I did
have a .ackrc in an ancestor directory, but I moved it to x.ackrc with
no change. I don't have a ~/.ackrc. The only ack environment variables are:

$ env | ack --nopager -i ack
ACK_PAGER=less -R
ACK_COLOR_MATCH=white

Version is:

$ ack --version
ack v3.5.0 (standalone version)
Running under Perl v5.30.3 at /usr/bin/perl

It's probably something simple and dumb I'm overlooking, but for now,
I'm baffled.

Thanks,
Brian

Andy Lester

unread,
Jul 31, 2023, 5:03:42 PM7/31/23
to ack-...@googlegroups.com


> On Jul 31, 2023, at 3:40 PM, Brian L. Matthews <blmat...@gmail.com> wrote:
>
> $ ack -l -r --nopager checkboxClass .
> $ ack -l -r --nopager checkboxClass *
> jquery.uniform.min.js


Minified Javascript files are automatically ignored by ack. See "ack --dump" to get a list of what those exclusions are. That's why when you say "ack ." it ignores it. (Really, you should just run ack without the . because ack assumes . for the directory)

In the case where you "ack whatever *", you are passing a list of files to ack to check. If you specify a filename on the command line, then ack assumes you know what you are asking to check, and bypasses the filtering logic.

Andy

Bill Ricker

unread,
Jul 31, 2023, 5:41:21 PM7/31/23
to ack-...@googlegroups.com
What Andy said.


Longer form --
The reason * will find a file that . doesn't is that Ack's concept of interesting vs ignorable files is set aside if a specific file or list of files is provided,
and since * is interpreted by the shell, Ack sees a specific list of files.
Meaning that `ack --type=js *` will NOT limit to just js  !! ;
the user is trusted to have typed *.js if that's what they meant, and the conflicting --type is ignored. (and arguably should give a warning?)
When given a starting directory, it still uses its idea of ^interesting^.
Hence * is different from . for Ack .
(* is different from . for grep also: in that hidden .files aren't expanded by the shell's * , but ack and `grep -r `will look at them from ./  .)

Minimized JavaScript (*.min.js) is generally thought to be unreadable; as you say, very long lines!,
so in the default state,  *.min.js is not considered interesting.
Even if you type --type=js .
(We have received a request ticket to allow windowing of *.min.js long lines ...
but without that, it's usable only with the -l flag, as you did!
Warning: ack checkboxClass *.js will match *.min.js as well as nice *.js, since it expands by shell,  and thus dump the long lines. But that's not recursive.)

How is this done?
The default config (from $wherever/lib/App/Ack/ConfigDefault.pm and as seen in Andy's ack --dump output ) includes
--ignore-file=match:/[.-]min[.]js$/

Workaround(s) -
Aside from
using  * , or ack -l ${pattern} *.min.js, or -l *.js,  you can override all the defaults seen in ack --dump by
--ignore-ack-defaults
which is even stronger than --noenv  (which ignores global ackrc as well as any ENV vars)
but that guts out all of the --type definitions plus other stuff in --dump.
( so you wouldn't want to put that in a ./.ackrc  unless you saved ack --dump >> .ackrc  and deleted what you didn't like.)

Alas i don't know of a way to cancel built-in or prior ackrc/env --ignore-{dir,file}= directives without purging everything with --ignore-ack-defaults ?
But when you need to find minimized JS, it's there for you.

If you want to scan only the minimized js, but recursively,
ack -g 'min[.]js$' --ignore-ack-defaults | ack -x -l checkboxClass
will do.
DIAGNOSTICS
You can see what files Ack would look at with a given * or . or ${directory} argument, and what Types they're considered, by
ack  -f --show-types ${options} ${paths}
try path = . or * or a short list; try options = " ", " --type=js "  or "   --ignore-ack-defaults "
Note that --type=js *  is a useless combination.
If you try both  --type=js    --ignore-ack-defaults
you'll find that js is undefined with defaults ignored, all will be considered. 

Brian L. Matthews

unread,
Jul 31, 2023, 7:58:11 PM7/31/23
to ack-...@googlegroups.com
On 7/31/23 2:03 PM, Andy Lester wrote:
>> On Jul 31, 2023, at 3:40 PM, Brian L. Matthews <blmat...@gmail.com> wrote:
>>
>> $ ack -l -r --nopager checkboxClass .
>> $ ack -l -r --nopager checkboxClass *
>> jquery.uniform.min.js
>>
>>
>> Minified Javascript files are automatically ignored by ack. See "ack --dump" to get a list of what those exclusions are.

Ok. I had done an ack --dump but was mainly looking at the types so I
missed the ignore-file. That explains it.

>> (Really, you should just run ack without the . because ack assumes . for the directory)

I normally do, just included it here to be super clear. Same for -r. I
usually just "ack pattern".

>> In the case where you "ack whatever *", you are passing a list of files to ack to check. If you specify a filename on the command line, then ack assumes you know what you are asking to check, and bypasses the filtering logic.

Yeah, makes sense that if I give it a file on the command line, it
should search that file.

On 7/31/23 2:41 PM, Bill Ricker wrote:

Thanks Bill for the longer explanation, and for verifying what I'd
figured, that there isn't really a good workaround. I always want to
search minified files, and would like to continue to use my normal "ack
pattern", so would like something I could throw in my .ackrc.

Andy, have you considered a --noignore-file options? I could see a
couple of ways it could work, either turn off a --ignore-file if a
--noignore-file is given with an exactly matching right-hand side (and
if there is no corresponding --ignore-file, maybe give a warning), or
collect the --noignore-files and if a file matches a --ignore-file,
match it against the --noignore-files.

Anyways, thanks for your responses!

Brian

Andy Lester

unread,
Jul 31, 2023, 8:03:15 PM7/31/23
to ack-...@googlegroups.com


> On Jul 31, 2023, at 6:58 PM, Brian L. Matthews <blmat...@gmail.com> wrote:
>
> Andy, have you considered a --noignore-file options? I could see a couple of ways it could work, either turn off a --ignore-file if a --noignore-file is given with an exactly matching right-hand side (and if there is no corresponding --ignore-file, maybe give a warning), or collect the --noignore-files and if a file matches a --ignore-file, match it against the --noignore-files.


This is the first the idea of a --noignore-file has come up. We do have --noignore-dir.

You can enter an issue about it at https://github.com/beyondgrep/ack3/issues

Thanks,
Andy

Bill Ricker

unread,
Jul 31, 2023, 9:06:22 PM7/31/23
to ack-...@googlegroups.com
figured, that there isn't really a good workaround. I always want to
search minified files, and would like to continue to use my normal "ack
pattern", so would like something I could throw in my .ackrc.

Options for your possibly odd use-case to make YOUR default let you use ack with minified JS -
any one of
  • If you install the non-standalone version of ack, you can just monkey-patch  lib/App/Ack/ConfigDefault.pm commenting out the two Minified JS lines.
    • if you clone from github, you can upgrade with git pull --fast-forward and keep your changes
    • (Or. If you prefer standalone, you can clone or install the sources and follow the README steps to build, and install the ack-standalone as ack.)
    • you could also monkeypatch directly in the bin/ack  (likely a copy of ack-standalone) , comment out the same 2 lines)
  • (echo "--ignore-ack-defaults"; ack --dump | ack -v  '(?=.*js).*min' | perl -plE  's/^(?=\S)/# /;') > ~/.ackrc 
    • (or copy contents of ConfigDefault.pm's heredoc into ~/.ackrc, commenting out the Minified JS section, and add --ignore-ack-defaults at the top;
      this makes nicer comments in .ackrc !)
Comment: since you like searching minified long-line files blocked as too ugly to view by
# minified JavaScript

--ignore-file=match:/[.-]min[.]js$/
--ignore-file=match:/[.]js[.]min$/
you may also want to search the things suppressed by
# minified CSS
--ignore-file=match:/[.]min[.]css$/
--ignore-file=match:/[.]css[.]min$/     
so i suggest you consider commenting out those two as well to minimize surprise, or not, as you prefer.

Brian L. Matthews

unread,
Aug 1, 2023, 2:37:25 PM8/1/23
to ack-...@googlegroups.com
On 7/31/23 6:06 PM, Bill Ricker wrote:

Options for your possibly odd use-case to make YOUR default let you use ack with minified JS -
any one of
  • If you install the non-standalone version of ack, you can just monkey-patch  lib/App/Ack/ConfigDefault.pm commenting out the two Minified JS lines.
    • if you clone from github, you can upgrade with git pull --fast-forward and keep your changes
    • (Or. If you prefer standalone, you can clone or install the sources and follow the README steps to build, and install the ack-standalone as ack.)
    • you could also monkeypatch directly in the bin/ack  (likely a copy of ack-standalone) , comment out the same 2 lines)
  • (echo "--ignore-ack-defaults"; ack --dump | ack -v  '(?=.*js).*min' | perl -plE  's/^(?=\S)/# /;') > ~/.ackrc 
    • (or copy contents of ConfigDefault.pm's heredoc into ~/.ackrc, commenting out the Minified JS section, and add --ignore-ack-defaults at the top;
      this makes nicer comments in .ackrc !)

Those are both possible options, and I'll probably end up doing the second, just because I already back up my .ackrc and copy it to new machines. If I have my own copy of ack, I'll have to remember to back up and copy that, and keep it up-to-date with the main copy. Admittedly that's not too hard, and I already do it with a couple other open source things I use, but it's "one more thing".


Comment: since you like searching minified long-line files blocked as too ugly to view by
# minified JavaScript
--ignore-file=match:/[.-]min[.]js$/
--ignore-file=match:/[.]js[.]min$/
you may also want to search the things suppressed by
# minified CSS
--ignore-file=match:/[.]min[.]css$/
--ignore-file=match:/[.]css[.]min$/     
so i suggest you consider commenting out those two as well to minimize surprise, or not, as you prefer.

Yes, I'd planned on commenting out/--noignore-file'ing minimized css too.

Thanks,
Brian
Reply all
Reply to author
Forward
0 new messages