Getting search hints through .htaccess or other dotfiles

Is there a way to get ack to search the file whose file name begins with . (e.g. .htaccess) without resorting to the --all or --unrestricted ?

I tried adding the following to my ~/.ackrc no avail:

 --type-set=apache=.htaccess 
+8
perl .htaccess ack dotfiles
source share
3 answers

It seems that ack does not recognize the file name, that all extensions; that is, when you specify the extension ".htaccess", ack looks for files with at least one character before this extension.

To get around this, you can use -u/--unrestricted in conjunction with the -G regex flag (to limit the search to files whose names match the regular expression). For example:

 $ ack -u -G '\.htaccess' pattern 
+4
source share

You cannot do this in ack 1.x. ack 2.0 will have more flexible ways to specify files.

0
source share

Updated @Sean answer for Ack 2

as they removed the two flags that @Sean used

ack 2 release notes say:

The -G option has been removed. Two patterns on the command line were mixed. In this command line:

 ack1 -G filepattern -i -w searchpattern 

which pattern does -i and -w do? Now, using ack 2.0, you can use the new -x to call file names from one ack call to another.

 ack2 -g -i filepattern | ack2 -x -w searchpattern 

and the -u flag (unlimited) is no longer needed. So you want:

 ack -g "\.htaccess" | ack -x pattern 

Or, for that matter, just use find to create a list of files (it is especially useful to find a file in dotfolder):

 find **/.hidden/complex-path/* | ack -x pattern 
0
source share

Source: https://habr.com/ru/post/651422/


All Articles