grox 0.8.0

Command-line tool that searches for regex matches in a file tree.
Documentation

Grox is a command-line tool that searches a file tree for regex matches.

Usage

For example,

$ grox the
(0) ./lib.rs:15: ... g to only retrieve the first match per f ...
(1) ./lib.rs:23: /// Path to the file.
(2) ./lib.rs:25: ... e number (1-up) of the match.
(3) ./lib.rs:47: ... n` - If specified, then only files whose  ...
(4) ./lib.rs:49: ... means only search the starting direct ...
(5) ./lib.rs:54: ... n't have access to the starting direct ...
(6) ./lib.rs:138: .and_then(|name| name.to ...
(7) ./lib.rs:139: .and_then(|name| name.ch ...
(8) ./lib.rs:340: ... oing to fold my clothes"
(9) ./history.rs:11: /// Path to the starting direct ...
(10) ./history.rs:41: ... d an `io:Error` if the starting direct ...
(11) ./history.rs:66: ... / * `file` - Path to the file.
(12) ./history.rs:70: ... sful and an error otherwise.
(13) ./history.rs:76: ... / Add a location to the history object.
(14) ./history.rs:80: ... / * `file` - Path to the file.
(15) ./history.rs:85: ... an `io::Error` if the path couldn't be  ...
(16) ./history.rs:95: /// Save the history object t ...
(17) ./history.rs:99: ... / * `file` - Path to the file.
(18) ./history.rs:103: ... sful and an error otherwise.
(19) ./history.rs:115: /// Path to the file.
(20) ./main.rs:29: ... hort, help = "Open the file for the spec ...
(21) ./main.rs:29: ... "Open the file for the specified resul ...
(22) ./open.rs:6: /// Facilitates the opening of a file  ...
(23) ./open.rs:8: /// Does the opener handle a g ...
(24) ./open.rs:12: ... ` - Name of/path to the editor.
(25) ./open.rs:19: /// Forms the `execv`` argume ...
(26) ./open.rs:23: ... / * `file` - Path to the file to be opened ...
(27) ./open.rs:28: ... s to `execv` minus the path to the edito ...
(28) ./open.rs:28: ... ` minus the path to the editor that shou ...
(29) ./open.rs:28: ... r that should go at the beginning.

By default the search starts with the current working directory. You can change this by -d DIRECTORY.

You can limit the directory search depth by -p DEPTH. A depth of 0 searches only the starting directory.

If you only want to get the names of the matching files, add -n:

$ grox the -n
(0) ./lib.rs
(1) ./history.rs
(2) ./main.rs
(3) ./open.rs

If you only want to search files whose names match a certain pattern, you can use -f:

$ grox the -f '\.rs$'

You can exclude directories from the search by -x:

$ grox some_pattern -x ./foo -x ./bar/baz

The excluded directories must be string-wise extensions of the starting directory (which, as a string, defaults to "."). For example, if the starting directory were ../foo, you could exclude ../foo/bar but not /path/to/foo/bar.

Opening files

You can open the n-th match in an editor with the -l option. For example, say you found these matches:

$ grox some_pattern
(0) file1.txt:55: ...
(1) file2:txt:2: ...

If you wanted to open up file1.txt, you could run the search again with -l:

$ grox some_pattern -l 0

If the EDITOR environment variable is set, then Grox will use the specified executable. Otherwise, it will try to use vim followed by vi. You can manually specify the editor by

$ grox some_pattern -l 0 -e less

If the chosen editor is either vim, vi, or code, then Grox will open up the file to the line containing the match.

History

When you run a search without -l and stdout is a terminal, a history file is created at ~/.grox_history.json. If you then re-run the exact same search with -l, Grox will grab the result from the history file instead of re-running the search.

Every search that doesn't use -l will overwrite the history file if it exists. That is, only the most recent search is saved.