npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

find-cli

v1.6.4

Published

An alternative to grep.

Downloads

616

Readme

Find-CLI

An alternative to grep.

Find looks for occurrences in files' contents that match a supplied glob, string or regular expression. It filters files and directories by way of configurable path matching rules that are also based on globs, strings and regular expressions. It is quite like grep but it is arguably more user friendly and surprisingly just as fast.

Find uses globs by default for matching both content and paths. Its use of them is slightly non-standard but hopefully de-mystifying. In fact there is is a section below devoted to how they are converted to regular expressions.

Installation

You can install Find via npm:

npm install --global find-cli

You may need to prepend sudo, depending on your setup.

If you would like to contribute or would simply like to have a look at the code, you can clone the repository with Git...

git clone https://github.com/djalbat/find-cli.git

...then install the dependencies with npm from within the project's root directory:

npm install

Usage

Find has the following commands and options:

  find [<options>] [<command>] [<argument>]

Commands:

  help                                     Show this help
 
  version                                  Show the version

  initialise                               Create a configuration file

  add-root-directory                       Add a root directory

  remove-root-directory                    Remove a root directory

  list-root-directories                    List the root directories
  
Options:

  --help|-h                                Show this help

  --version|-v                             Show the version

  --dry-run|-d                             Traverse the directories and files only

  --quietly|-q                             Do not show the directory and file path matching

  --format|-f                              Formatted output, shown only once the search completes.

  --glob|-g                                Treat the argument as a glob, which is the default.

  --regex|-g                               Treat the argument as a regular expression.

  --string|-s                              Treat the argument as a string.

  --interactive|-i                         Interactive mode, allowing the argument to be provided via stdin.

Setup

Suppose that you want to search your ~/Development directory. First run the following commands:

cd ~/Development
find initialise

This creates a .findrc configuration file in the ~/Development directory that under normal circumstances should not be edited by hand.

Now suppose that you also want to search a sibling ~/Sites directory. You can configure this additional root directory and see the results with the following commands:

find add-root-directory ../Sites/
find list-root-directories

Path rules

Once you have the root directories set up you can start to add the rules that filter the file and directory paths. Start with a dry run so that there is no need to specify what to search for:

find -d

Find works from four collections of rules for ignoring and permitting file and directory paths. It ignores paths first but can subsequently permit them. It must be able to match a rule to each path that it encounters. If not it will prompt you to configure one. For example, the very first file that it encounters may be its own .findrc configuration file. In that case it will ask you whether you want to ignore or permit that path and then prompt you for a glob, string or regular expression to match the path as a whole. The choice is yours but globs are the default and do not have delimiters.

.findrc     // gllob
".findrc"   // string
/\.findrc/  // regular expression

You may have several thousand files and directories that need matching and wildcards will obviously be needed. It can take several minutes to answer all the prompts but you can opt out at any time by hitting the enter key three times at any prompt. A little patience with the process and a couple of tries at it are recommended.

Once the rules are set up there is little more to do other than to search for occurrences, again using globs, strings or regular expressions. For example:

find -q START_OF_CONTENT
find -q "Query.fromExpression"
find -q /"[^"]*"/

The -q flag here suppresses the path matching messages. Only the occurrences will be shown once the search is complete.

Converting globs to regular expressions

Find differentiates between directory and file paths and this is important when converting globs. Directory paths must end with a slash. So:

/        // root directory
./       // current directory
../      // parent directory
foo/  
foo/bar/

Find will add the trailing slashes when matching directory paths. For example:

Ignore ../Sites/account.xomi.cloud/template/ */template/**/

Note that the root directory has been prepended, but only for clarity when showing messages. It is not prepended for the purpose of matching. A trailing slash has been prepended, however, and this has a bearing on how the glob is converted.

One thing to note is that you do not have to remember to prepend trailing slashes yourself when prompted for globs, strings or regular expressions ot match directory paths. Find will always add them.

Although non-standard, The presence of a trailing slash for directory paths means makes the conversion of globs to regular expressions easier. Here is a list of some of the conversions:

| Glob | Regular expression | Description | |-------|--------------------|----------------------| | **/ | (?:[^/]*\\/)* | Repeated directories | | */ | [^/]*\\/ | Single directory | | / | \\/ | Directory | | ** | .* | Repeated wildcard | | * | .+? | Single wildcard |

Character classes and alternatives are also supported. Their conversions are more or less standard.

Command line considerations

Node is only supplied with the parsed command string and since shells remove double quotes, the following...

find -q "START_OF_CONTENT"

...may as well be:

find -q START_OF_CONTENT

In either case the argument will be treated as a glob because Find does not see any double quotes.

There are two ways around this.

  1. You can use the interactive mode:
find -qi

This will allow you to input "START_OF_CONTENT" by hand, so to speak. Since Node is now reading stdin rather than a parsed command string, the quotes will remain.

  1. Use the -s flag:
find -qs START_OF_CONTENT

This coerces Find into treating the argument as a string irregardless of the missing double quotes.

There is also the -r flag for regular expressions if you do not want to type the / regular expression delimiters, by the way. And lastly, the -g flag for globs is provided for the sake of completeness but since globs are the default it is never really needed.

Contact