Add SCons files to ack searches
I love t开发者_JAVA百科he code search utility ack
. It is smart enough to look through Makefiles, but doesn't know about the SConstruct and SConscript files that scons uses. How do I add those to the files that ack will look in?
Here is a patch that treats SCons files like make files:
--- ~/bin/ack-old 2011-06-01 15:43:51.000000000 -0600
+++ ~/bin/ack 2011-06-01 15:42:09.000000000 -0600
@@ -1583,6 +1583,8 @@
return 'skipped' unless is_searchable( $basename );
+ return ('python',TEXT) if $basename eq 'SConstruct' || $basename eq 'SConscript';
+
my $lc_basename = lc $basename;
return ('make',TEXT) if $lc_basename eq 'makefile' || $lc_basename eq 'gnumakefile';
return ('rake','ruby',TEXT) if $lc_basename eq 'rakefile';
This can't be done using ack's type sets. Makefiles and Rakefiles are hard-coded in the source. I thought you could add a scons type by modifying $HOME/.ackrc
and adding --type-set=scons=SConstruct,SConscript
, but that will search for a file that ends in ".SConstruct" or ".SConscript".
The easiest workaround is to add the -a (all file types) flag to ack.
If you just want ack to search and be able to filter the SConstruct somehow, then you could add #!/usr/bin/python
as the first line of the SConstruct file. Ack will then treat the file as python source code, and you can filter with --python
.
A new ack2 is in development which will allow exact file matching in the .ackrc file. That will enable easier support for Scons and Jam.
精彩评论