Facade for basic find tool that recursively matches files by globs
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin
klepto
.gitignore
LICENSE
README.md
setup.py

README.md

Klepto prints files in the file system matching at least one glob using fnmatch, starting in the working directory.

I made this solely for convenience after getting tired of bending native shell search commands to the use cases shown below.

How it works

In the most basic case, Klepto prints absolute paths to files that match a glob. Klepto will check every file in the working directory, and all files in subdirectories recursively.

$ cd ~/code
$ klepto "*.js"

/home/me/code/A.js
/home/me/code/extra/F.js
/home/me/code/extra/G.js
/home/me/code/extra/E.js
/home/me/code/extra/D.js
/home/me/code/subdir/B.js
/home/me/code/subdir/C.js

You may exclude a directory from the output.

$ klepto --exclude extra "*.js"

/home/me/code/A.js
/home/me/code/subdir/C.js
/home/me/code/subdir/B.js

You may exclude more than one directory, if desired.

$ klepto --exclude extra --exclude subdir "*.js"

/home/me/code/A.js

Klepto can match against multiple globs. By default, klepto prints files that match any of the specified globs.

$ klepto --exclude extra "*.js" "*.css"

/home/me/code/X.css
/home/me/code/A.js
/home/me/code/subdir/Y.css
/home/me/code/subdir/C.js
/home/me/code/subdir/B.js

However, you can specify that klepto prints files that match ALL globs. This example prints only .js files in subdir.

$ klepto --all "*.js" "*subdir*"

/home/me/code/subdir/C.js
/home/me/code/subdir/B.js

This is almost the same as saying klepto "*subdir/*.js".

You can also count the number of results.

$ klepto --all --number "*.js" "*subdir*"
2

Finally, you can print relative paths.

$ klepto --all --relative "*.js" "*subdir*"
./subdir/C.js
./subdir/B.js

Gotchas

  • To avoid unwanted wildcard expansions, be sure to quote or escape your globs.
  • Globs match against the absolute path to each candidate file. klepto "mydir/*.txt" will have no output, but klepto "*mydir/*.txt" will.

Command line reference

klepto [-h] [-e EXCLUDE] [-c CONFIG] [-a] GLOB [GLOB ...]
  • GLOB: Positional sequence of at least one glob used when matching files.
  • --exclude/-e: Specifies the name of one directory to never scan when matching files. You may specify --exclude multiple times to exclude more than one directory.
  • --config/-c: Specifies location of JSON-serialized config file. Defaults to ~/.kleptorc.json. See Configuration
  • --all/-a: If set, prints only files that match all globs, instead of files that match any one glob.
  • --relative/-r: If set, prints relative paths to files instead of absolute paths.
  • --number/-n: If set, prints number of matches instead of paths.

Configuration

Store configuration data in a JSON-serialized file. An example config file might look like this:

{
	"exclude": [
		"node_modules",
		"bower_components"
	]
}

You can specify the location of this file using --config or -c.

$ klepto --config /path/to/config.json

By default, klepto will look for a ~/.kleptorc.json if you do not specify a config file.

Configuration properties

  • exclude - Array of directory names to never include in the output. These are not globs. If you specify directory names using --exclude/-e, they will merge with the names specified in the config file.