Crates.io | comby-search |
lib.rs | comby-search |
version | 0.2.1 |
source | src |
created_at | 2023-03-13 23:59:40.534984 |
updated_at | 2023-03-16 00:24:47.150196 |
description | Structural Code Search using Comby |
homepage | https://github.com/huytd/comby-search |
repository | https://github.com/huytd/comby-search |
max_upload_size | |
id | 809348 |
size | 440,655 |
Comby Search is a convenience wrapper around Comby to provide the code searching functionality.
Because Comby by default provided the code rewrite function and does not have a pretty output when doing -match-only
. Comby Search
wrapped around Comby and parse the -match-only
output to make it easier to search and see the result.
And why using Comby? See here for more details: https://github.com/comby-tools/comby#isnt-a-regex-approach-like-sed-good-enough
But TL;DR: Comby provides a better search comparing to Regex. It handles whitespaces automatically (if you ever tried search multilines of codes in Regex, you'll know), context aware (for example, it will not match commented code),...
Comby Search rely on these tools, you should have them installed first:
You can install via cargo
with:
cargo install comby-search
Or compile it from source.
Usage: cb [OPTIONS] <QUERY>
Arguments:
<QUERY> Your code search query
Options:
-f, --filter <PATTERN> File filter pattern, for example: '*.ts,!*.spec.ts'
-l, --line-margin <MARGIN> Number of lines to display before and after the matched search result
-h, --help Print help
To start a new search, run the command below. See Comby's Documentation for more information about the search syntax.
$ cb '<search query>'
For example:
$ cb 'struct :[A] { :[B] }'
You can also limit the scope of the search to some specific files with:
$ cb -f '*.ts,*.java,!*.js' 'struct :[A] { :[B] }'
By default, the matched result will be displayed with a margin of 3 lines before and after, you can change this with the --line-margin
or -l
option:
$cb -l 10 'foo'
Here are some example search with cb
.
$ cb -f '*.tsx,*.jsx' 'const :[1] = (:[2]) => { :[3] }'
superFoo
function with an empty string as argument?$ cb 'superFoo(:[2] "" :[3])'
$ cb -f '!*Test.java' 'for ([:1]) { :[2] }'
$ cb -f '*.rs' 'fn :[1] (:[2]) -> String'
$ cb 'trait :[1] { fn :[2](:[3]); }'
# and
$ cb 'trait :[1] { fn :[2](:[3]) -> :[4]; }'