eliben / pss

pss is a power-tool for searching inside source code files.
Other
327 stars 46 forks source link

Easier support for custom file extensions #23

Closed pekkaklarck closed 10 years ago

pekkaklarck commented 10 years ago

I'm working with custom file extension .robot (test data files for http://robotframework.org) and by default pss doesn't, as designed, look into them. I can simply use -a to look everywhere, but if I want to look only to those files I need to use -aG '.*\.robot'. Not so nice if you are using pss with such files a lot. There are obviously many other custom file types too, for example, .tmpl is mentioned issue #1 comments.

It would be convenient if there was an option to easily limit searching to a certain file extension. Basically I would like to use something like -E robot instead of -aG '.*\.robot'. Notice that I would like both to avoid writing a regexp when I don't really need it (robot vs. '.*\.robot') and would like -a to be implied. (I was rather surprised I needed to use it with -G, might be a good idea to mention that in its docs.)

I'm willing to implement this functionality myself. Mainly wanted to submit an issue first to hear what you think about it before starting to create a pull request. Should also decide what is a good short option for this usage and is long option needed too.

I'm also looking for a way to add these custom files into a list of files that pss looks by default. That's definitely a topic for a separate issue, most likely my needs are already covered by #1.

eliben commented 10 years ago

I think #4 offers a more generic approach to this, no?

pekkaklarck commented 10 years ago

4 is definitely similar and solves the problem to "add these custom files into a list of files that pss looks by default" that I mentioned in the end of the description. It doesn't make it much easier to restrict search only to certain custom extension. Compare these possibilities:

pss -aG '.*\.robot' pattern                    # works now
pss -E robot pattern                           # proposed by this issue
pss --type-add robot=.robot --robot pattern    # proposed by issue #4

I'd probably keep on using the first option even if #4 was implemented because using it so verbose. Needing to type robot three times is a bit too much.

eliben commented 10 years ago

I think I already laid this philosophy down somewhere, but can't find it now, so I'll repeat at least partially: it is not my goal to build any option under the sun into pss. Anyone who's looked at its code noticed that the flag parsing code is already super complicated because of the sheer amount of options supported.

I personally have wrapper scripts around pss that just invoke it with extra arguments for special situations - I think this can work for anyone. Then verbosity is not a real problem. In this respect the --type-add proposal is superior because if your pss wrapper actually calls:

pss --type-add robot=.robot "$@"

Then you have your enhanced pss, all the rest works just fine.

What I could consider (I remember someone proposed implementing it but then lost interest) is supporting configuration files that would make specifying lots of options easier. pss could then be pointed to such configuration files, so you'd have:

 pss --config <my_pss_config> $@

In your wrapper script. Or multiple wrapper scripts with multiple configs.

pekkaklarck commented 10 years ago

Fair enough.