Giter VIP home page Giter VIP logo

comby-search's Introduction

Comby Search

Comby Search is a convenience wrapper around Comby to provide the code searching functionality.

Why Comby Search? Why Comby?

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),...

Dependencies

Comby Search rely on these tools, you should have them installed first:

Install

You can install via cargo with:

cargo install comby-search

Or compile it from source.

Usage

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'

Examples

Here are some example search with cb.

  1. Find all arrow functions in TSX files
$ cb -f '*.tsx,*.jsx' 'const :[1] = (:[2]) => { :[3] }'
  1. Is there any call to the superFoo function with an empty string as argument?
$ cb 'superFoo(:[2] "" :[3])'
  1. Find all for loop in all Java files, but not in test files
$ cb -f '!*Test.java' 'for ([:1]) { :[2] }'
  1. Find all Rust functions that return a String
$ cb -f '*.rs' 'fn :[1] (:[2]) -> String'
  1. Find Rust traits (can you tell the different?)
$ cb 'trait :[1] { fn :[2](:[3]); }'

# and

$ cb 'trait :[1] { fn :[2](:[3]) -> :[4]; }'

comby-search's People

Contributors

huytd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

comby-search's Issues

line margin `-l` does not work with 0

Hi there, thanks a lot for building comby-search. It's been absolutely helpful wrapping comby and searching together!

Unfortunately, there's an issue with the line margin property. I was expecting it to show no margins when passing 0 to it and only the matched line. Also, when I pass other values, it returns a different margin. An example is shown below

$ ls
test.txt
$ bat test.txt     
───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: test.txt
───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ a
   2   │ cat
   3   │ in
   4   │ the
   5   │ hat
───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
$ cb -f '*.txt' 'cat' -l 0
test.txt
   2 │ cat
   3 │ in

I was expecting it to only show

$ cb -f '*.txt' 'cat' -l 0
test.txt
   2 │ cat
Also, these outputs don't match for `1` & `2` ``` $ cb -f '*.txt' 'cat' -l 1 test.txt 1 │ a 2 │ cat 3 │ in 4 │ the $ cb -f '*.txt' 'cat' -l 2 test.txt 1 │ a 2 │ cat 3 │ in 4 │ the 5 │ hat ```

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.