4 releases (2 breaking)
new 0.3.0 | Mar 29, 2025 |
---|---|
0.2.0 | Mar 26, 2025 |
0.1.1 | Mar 24, 2025 |
0.1.0 | Mar 24, 2025 |
#77 in #regex
259 downloads per month
24KB
529 lines
Grox is a command-line tool that searches a file tree for regex matches.
Usage
For example,
$ grox the
(1) ./lib.rs:19: ... / * `file` - Path to the file.
(2) ./lib.rs:20: ... e number (1-up) of the match.
(3) ./lib.rs:50: ... rror message if either `max_depth` was ...
(4) ./lib.rs:51: ... n't have access to the starting direct ...
(5) ./lib.rs:151: .and_then(|name| name.to ...
(6) ./lib.rs:152: .and_then(|name| name.ch ...
(7) ./lib.rs:314: ... oing to fold my clothes"
(8) ./main.rs:18: ... tory. Defaults to the current working ...
(9) ./main.rs:28: ... hort, help = "Open the file for the spec ...
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 1 searches only the starting directory.
If you only want to get the names of the matching files, add -n
:
$ grox the -n
(1) ./lib:rs
(2) ./main.rs
If you only want to search files whose names match a certain pattern, you can use -f
:
$ grox the -f '\.rs$'
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
(1) file1.txt:55: ...
(2) file2:txt:2: ...
If you wanted to open up file1.txt, you could run the search again with -l
:
$ grox some_pattern -l 1
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 1 -e less
If the chosen editor is either vim or vi, then Grox will open up the file to the line containing the match.
History
When you run a search without -l
, 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.
Dependencies
~4–12MB
~136K SLoC