Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to search a particular word or entry inside a sub folder in a repository on github

I am just looking for an example ( the correct command to fire in the advance search at github ) about searching a word inside a folder of a particular repository. I guess this will involve the "path:" option but not sure how to use it

As an example I need to search for a function name "clean" or a test case for "clean" or similar function inside the jquery test suite at the following location -
https://github.com/jquery/jquery/tree/master/test

I understand there are some filters like repo: and path: provided by github but not sure how to use them.

Also I am not satisfied with an answer posted for a similar question at - Search a github repository for the file defining a given function

I understand I can fork it to my local machine and do a search there but I don't want to download the whole repository simply to search it. I just need to search it online at the github site itself.

Thanks in advance !!

like image 413
Anmol Saraf Avatar asked Jul 30 '12 13:07

Anmol Saraf


People also ask

How do I search the contents of a file in GitHub?

Select to search in current repository, not "All GitHub". It will display all "Entry" in particular file. Just to add a little something: the syntax seems to be <search term> filename:<filename> and you may search for it in your organization only (by adding org:<your organization name> .

How do I find functions on GitHub?

Finding all references of a function or method You can find all references for a function or method within the same repository by clicking the function or method call in a file, then clicking the References tab.


1 Answers

I get 41 result with this query.

The key is to specify the user/reponame, not the the reponame:

repo:hadley/ggplot2

Combined with wildcard for the path argument, I select only one argument with this query:

repo:hadley/ggplot2 facet_wrap path:inst/*.r

So, for path, the key is to add a wildcard (which doesn't seem to be documented anywhere).
path:inst/ alone won't work. path:* or path:*.r will.


From the comments:

I need to find "beforeSend" entry which is in this file - "jquery / test / unit / ajax.js" at github.com/jquery/jquery/blob/master/test/unit/ajax.js but when I fire repo:jeresig/jquery beforeSend path:jquery/test/unit*.js in the advance search I don't get any results.
I am also confused which user should I use as jquery has many contributors like John Resig, timmywil

In this case:

  • the repo is jquery/jquery (no need for a username here)
  • the path: directive to use must not repeat the repo name: so, path:test/unit*.js, not path:jquery/test/unit*.js
     repo:jquery/jquery beforeSend path:test/unit*.js

will work, and provide 4 results within JQuery Code.

like image 187
VonC Avatar answered Sep 22 '22 04:09

VonC