Grep with human-friendly search output

Overview

hgrep: Human-friendly GREP

CI crate

hgrep is a grep tool to search files with given pattern and print the matched code snippets with human-friendly syntax highlighting. In short, it's a fusion of bat and grep or other alternatives like ripgrep.

This is similar to -C option of grep command, but hgrep focuses on human readable outputs. hgrep is useful to survey the matches with contexts around them. When some matches are near enough, hgrep prints the lines within one code snippet. Unlike grep -C, hgrep adopts some heuristics around blank lines to determine efficient number of context lines.

Example:

# With standard grep
grep -nH pattern -R ./dir | hgrep

# With grep alternative tools
rg -nH pattern ./dir | hgrep

As an optional feature, hgrep has builtin grep implementation thanks to ripgrep as library. It's a subset of rg command. And it's faster when there are so many matches since everything is done in the same process.

Example:

# Use builtin subset of ripgrep
hgrep pattern ./dir

Please see the usage section for more details.

screenshot

Installation

Binary releases

Visit the releases page and download the zip file for your platform. Unarchive the file and put the executable file in some $PATH directory. Currently the following targets are supported. If you want a binary for some other platform, feel free to make an issue to request it.

  • Linux (x86_64)
  • macOS (x86_64)
  • Windows (x86_64)

Via Homebrew

By adding hgrep repository as Homebrew tap, hgrep command can be installed and managed via Homebrew. Currently only for x86_64 macOS and Linux.

brew tap "rhysd/hgrep" "https://github.com/rhysd/hgrep"
brew install hgrep

Via cargo package manager

cargo install hgrep

If you always use hgrep with reading the grep output from stdin and don't want the builtin ripgrep feature, it can be omitted. This reduces the number of dependencies, installation time, and the binary size.

cargo install hgrep --no-default-features

Usage

Eat grep -nH output

hgrep takes grep results via stdin. Since hgrep expects file paths and line numbers in each line of the output, -nH is necessary at grep command.

grep -nH pattern -R paths... | hgrep [options...]

grep alternative tools like ripgrep, ag, pt, ... are also available because they can output results compatible with grep -nH.

rg -nH pattern paths... | hgrep [options...]

When you want a pager, please use external commands like less.

grep -nH pattern -R paths... | hgrep [options...] | less -R

By default, hgrep shows at least 5 lines and at most 5 lines as context of a match. How many context lines is determined by some heuristics around blank lines for efficiency. Minimum context lines can be specified by -c and Maximum context lines can be specified by -C. If you don't want the heuristics, specify the same value to the options like -c 10 -C 10.

# At least 10 context lines and at most 20 context lines
grep -nH pattern -R paths... | hgrep -c 10 -C 20

Builtin ripgrep

Optionally hgrep provides builtin grep implementation. It is a subset of ripgrep since it's built using ripgrep as library. And it's faster when there are so many matches because everything is done in the same process. The builtin grep feature is enabled by default and can be omitted by installing it with --no-default-features.

hgrep [options...] pattern paths...

Though almost all useful options are implemented, the builtin grep implementation is a subset of ripgrep. If you need full functionalities, use rg command and eat its output by hgrep via stdin. Currently there are the following restrictions.

  • Preprocessor is not supported (e.g. search zip files)
  • Memory map is not used until --mmap flag is specified
  • Adding/Removing file types are not supported. Only default file types are supported (see --type-list)
  • .ripgreprc config file is not supported

Change color theme and layout

Default color theme is Monokai Extended respecting bat command's default. Other theme can be specified via --theme option. To know names of themes, try --list-themes flag.

grep -nH ... | hgrep --theme Nord

And hgrep respects BAT_THEME environment variable.

export BAT_THEME=OneHalfDark

Default layout is 'grid' respecting bat command's default. To print the matches without border lines, --no-grid option is available.

grep -nH ... | hgrep --no-grid

And hgrep respects BAT_STYLE environment variable. When plain or header or numbers is set, hgrep removes border lines.

export BAT_STYLE=numbers

Command options

  • Common options
    • --min-context NUM (-c): Minimum lines of leading and trailing context surrounding each match. Default value is 5
    • --max-context NUM (-C): Maximum lines of leading and trailing context surrounding each match. Default value is 10
    • --no-grid (-G): Remove border lines for more compact output. --grid flag is an opposite of this flag
    • --tab NUM: Number of spaces for tab character. Set 0 to pass tabs through. Default value is 4
    • --theme THEME: Theme for syntax highlighting. Default value is the same as bat command
    • --list-themes: List all theme names available for --theme option
  • Only for builtin ripgrep
    • --no-ignore: Don't respect ignore files (.gitignore, .ignore, etc.)
    • --ignore-case (-i): When this flag is provided, the given patterns will be searched case insensitively
    • --smart-case (-S): Search case insensitively if the pattern is all lowercase. Search case sensitively otherwise
    • --glob GLOB... (-g): Include or exclude files and directories for searching that match the given glob
    • --glob-case-insensitive: Process glob patterns given with the -g/--glob flag case insensitively
    • --fixed-strings (-F): Treat the pattern as a literal string instead of a regular expression
    • --word-regexp (-w): Only show matches surrounded by word boundaries
    • --follow (-L): When this flag is enabled, hgrep will follow symbolic links while traversing directories
    • --multiline (-U): Enable matching across multiple lines
    • --multiline-dotall: Enable "dot all" in your regex pattern, which causes '.' to match newlines when multiline searching is enabled
    • --crlf: about(r"When enabled, hgrep will treat CRLF (\r\n) as a line terminator instead of just \n. This flag is useful on Windows
    • --mmap: Search using memory maps when possible. mmap is disabled by default unlike hgrep
    • --max-count NUM (-m): Limit the number of matching lines per file searched to NUM
    • --max-depth NUM: Limit the depth of directory traversal to NUM levels beyond the paths given
    • --max-filesize NUM: Ignore files larger than NUM in size
    • --line-regexp (-x): Only show matches surrounded by line boundaries. This is equivalent to putting ^...$ around all of the search patterns
    • --pcre2 (-P): When this flag is present, hgrep will use the PCRE2 regex engine instead of its default regex engine
    • --type TYPE (-t): Only search files matching TYPE. This option is repeatable
    • --type-not TYPE (-T): Do not search files matching TYPE. Inverse of --type. This option is repeatable
    • --type-list: Show all supported file types and their corresponding globs

See --help for full list of options.

Generate completion scripts

Shell completion script for hgrep command is available. --generate-completion-script option generates completion script and prints it to stdout. Bash, Zsh, Fish, PowerShell, Elvish are supported. See --help for argument of the option.

This is an example to setup the completion script on Zsh.

# Let's say we set comps=~/.zsh/site-functions
hgrep --generate-completion-script zsh > ~/.zsh/site-functions/_hgrep

Alternatives

Some other alternatives instead of using hgrep.

Small ShellScript to combine ripgrep and bat

ripgrep and bat are well-designed tools so they can be used as building parts of small script.

rg -nH ... | while IFS= read -r line; do
  # Parse $line and calculate the range of snippet and highlighted lines
  file=...
  lines=...
  range=...

  # Show matched snippet
  bat -H ${lines} -r ${range} ${file}
done

It works fine but hgrep is more optimized for this usage.

  • When the matches are near enough, the lines are printed in one snippet.
  • Performance is better than running bat process per matched line.
  • hgrep computes efficient context lines based on some heuristics.
  • hgrep is available where ShellScript is unavailable (e.g. PowerShell).

Fuzzy finder like fzf with bat preview window

Fuzzy finder like fzf provides a preview window functionality and bat can print the match in the preview window.

grep -nH ... | \
    fzf --preview='bat --pager never --color always -H {2} -r {2}: -p {1}' --delimiter=:

This usage is great when you need the incremental search, but you need to check each preview of matches one by one.

hgrep focuses on surveying all the matches.

Bug reporting

Please make an issue on GitHub. Ensure to describe how to reproduce the bug.

License

hgrep is distributed under the MIT license.

Comments
  • Homebrew not working

    Homebrew not working

    ❯ brew tap "rhysd/hgrep" "https://github.com/rhysd/hgrep"
    brew install hgrep
    ==> Downloading https://github.com/rhysd/hgrep/releases/download/v0.2.1/hgrep-v0.2.1-x86_64-apple-darwin.zip
    Already downloaded: /Users/$USER/Library/Caches/Homebrew/downloads/712103ea480f4147dde712234225835a35bc2a2213180120913b81329051bd47--hgrep-v0.2.1-x86_64-apple-darwin.zip
    ==> Installing hgrep from rhysd/hgrep
    Error: Failure while executing; `/Users/$USER/homebrew/Cellar/hgrep/0.2.1/bin/hgrep --generate-completion-script zsh` was terminated by uncaught signal ABRT. Here's the output:
    ❯ /Users/$USER/homebrew/Cellar/hgrep/0.2.1/bin/hgrep --generate-completion-script zsh
    zsh: no such file or directory: /Users/$USER/homebrew/Cellar/hgrep/0.2.1/bin/hgrep
    

    Don't think it is related to OS, but if you need I will share.

    bug 
    opened by anhdle14 15
  • v0.1.6: compilation error with Rust 1.56.0

    v0.1.6: compilation error with Rust 1.56.0

    Compilation failed on macOS Catalina 10.15.7 when trying to compile hgrep v0.1.6 using Rust 1.56.0:

    error: couldn't read src/../assets/bat/assets/syntaxes.bin: No such file or directory (os error 2)
      --> src/syntect.rs:27:31
       |
    27 | const SYNTAX_SET_BIN: &[u8] = include_bytes!("../assets/bat/assets/syntaxes.bin");
       |                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
       = note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info)
    
    error: couldn't read src/../assets/bat/assets/themes.bin: No such file or directory (os error 2)
      --> src/syntect.rs:28:30
       |
    28 | const THEME_SET_BIN: &[u8] = include_bytes!("../assets/bat/assets/themes.bin");
       |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
       = note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info)
    
    error: could not compile `hgrep` due to 2 previous errors
    
    
    opened by herbygillot 14
  • musl binary is not statically linked

    musl binary is not statically linked

    I downloaded the latest musl binary from GitHub releases, but am unable to run it.

    ❯ /spare/ssd/szafar/apps/bin/hgrep
    zsh: no such file or directory: /spare/ssd/szafar/apps/bin/hgrep
    
    ❯ ldd /spare/ssd/szafar/apps/bin/hgrep
            linux-vdso.so.1 (0x00007fff4bdf7000)
            libgtk3-nocsd.so.0 => /lib/x86_64-linux-gnu/libgtk3-nocsd.so.0 (0x00007fad62b28000)
            libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fad62b0d000)
            libc.musl-x86_64.so.1 => not found
            libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fad62b07000)
            libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fad62ae4000)
            libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fad628f2000)
            /lib/ld-musl-x86_64.so.1 => /lib64/ld-linux-x86-64.so.2 (0x00007fad633d2000)
    
    ❯ file /spare/ssd/szafar/apps/bin/hgrep
    /spare/ssd/szafar/apps/bin/hgrep: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-x86_64.so.1, with debug_info, not stripped
    
    opened by dufferzafar 7
  • hgrep on NetBSD

    hgrep on NetBSD

    Hi,

    I've packaged and merged hgrep into the main pkgsrc branch, https://mail-index.netbsd.org/pkgsrc-changes/2021/10/20/msg242216.html

    This means the package is now available from the official repositories for NetBSD.

    Thank you for this awesome tool. /pin

    opened by 0323pin 6
  • Panic when eating input from `rg --vimgrep` and max context=0

    Panic when eating input from `rg --vimgrep` and max context=0

    This happens especially when running with rg --vimgrep which can result in a line with more than one match will be printed more than once. When running hgrep -C0 this will result in a panic on the duplicate line. (Theoretically this could be considered invalid input, but I guess hgrep should handle it more gracefully than panicking)

    I can reproduce this using the 0.2.6 build on github release and also compiling latest from main branch.

    1. Create a file:
    abc
    def
    
    1. Then run rg --vimgrep . file | hgrep -c0 -C0
    2. Resulting in the following panic message:
    thread '<unnamed>' panicked at 'line 2 > chunk 1', /home/runner/work/hgrep/hgrep/src/chunk.rs:162:13
    stack backtrace:
       0:     0x5623558a1d34 - std::backtrace_rs::backtrace::libunwind::trace::h22893a5306c091b4
                                   at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
       1:     0x5623558a1d34 - std::backtrace_rs::backtrace::trace_unsynchronized::h29c3bc6f9e91819d
                                   at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
       2:     0x5623558a1d34 - std::sys_common::backtrace::_print_fmt::he497d8a0ec903793
                                   at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/sys_common/backtrace.rs:66:5
       3:     0x5623558a1d34 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h9c2a9d2774d81873
                                   at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/sys_common/backtrace.rs:45:22
       4:     0x562355725d1c - core::fmt::write::hba4337c43d992f49
                                   at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/fmt/mod.rs:1194:17
       5:     0x56235589f295 - std::io::Write::write_fmt::heb73de6e02cfabed
                                   at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/io/mod.rs:1655:15
       6:     0x5623558a37ae - std::sys_common::backtrace::_print::h63c8b24acdd8e8ce
                                   at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/sys_common/backtrace.rs:48:5
       7:     0x5623558a37ae - std::sys_common::backtrace::print::h426700d6240cdcc2
                                   at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/sys_common/backtrace.rs:35:9
       8:     0x5623558a37ae - std::panicking::default_hook::{{closure}}::hc9a76eed0b18f82b
                                   at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:295:22
       9:     0x5623558a34dd - std::panicking::default_hook::h2e88d02087fae196
                                   at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:314:9
      10:     0x5623558a3d55 - std::panicking::rust_panic_with_hook::habfdcc2e90f9fd4c
                                   at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:698:17
      11:     0x5623558a3c64 - std::panicking::begin_panic_handler::{{closure}}::he054b2a83a51d2cd
                                   at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:588:13
      12:     0x5623558a2264 - std::sys_common::backtrace::__rust_end_short_backtrace::ha48b94ab49b30915
                                   at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/sys_common/backtrace.rs:138:18
      13:     0x5623558a39cd - rust_begin_unwind
                                   at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:584:5
      14:     0x562355664d83 - core::panicking::panic_fmt::h366d3a309ae17c94
                                   at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:143:14
      15:     0x5623557c3a9a - <hgrep::chunk::Files<I> as core::iter::traits::iterator::Iterator>::next::h5ee4291e70bebdc3
      16:     0x56235579be59 - <rayon::iter::par_bridge::IterParallelProducer<Iter> as rayon::iter::plumbing::UnindexedProducer>::fold_with::h0dca500009f9e028
      17:     0x5623557955a2 - rayon::iter::plumbing::bridge_unindexed_producer_consumer::h223e4423a9933835
      18:     0x5623557a2ca7 - std::panicking::try::hf0836b1c957853cc
      19:     0x5623557cb66d - rayon_core::registry::in_worker::he45b25a872d14469
      20:     0x562355795507 - rayon::iter::plumbing::bridge_unindexed_producer_consumer::h223e4423a9933835
      21:     0x5623557a2ca7 - std::panicking::try::hf0836b1c957853cc
      22:     0x5623557cb66d - rayon_core::registry::in_worker::he45b25a872d14469
      23:     0x562355795507 - rayon::iter::plumbing::bridge_unindexed_producer_consumer::h223e4423a9933835
      24:     0x5623557a2ca7 - std::panicking::try::hf0836b1c957853cc
      25:     0x5623557cb66d - rayon_core::registry::in_worker::he45b25a872d14469
      26:     0x562355795507 - rayon::iter::plumbing::bridge_unindexed_producer_consumer::h223e4423a9933835
      27:     0x5623557a2ca7 - std::panicking::try::hf0836b1c957853cc
      28:     0x5623557b5895 - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::h0b572bc3ae82dd95
      29:     0x5623557a260f - std::panicking::try::h5cef0bae059587cf
      30:     0x5623557b8ff3 - <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute::h5b2d03e421fd52dd
      31:     0x56235566e2e5 - rayon_core::registry::WorkerThread::wait_until_cold::h8e688ed76ab0d924
      32:     0x562355806d36 - rayon_core::registry::ThreadBuilder::run::h5b1fb0c08159930b
      33:     0x5623558092d1 - std::sys_common::backtrace::__rust_begin_short_backtrace::hff0e2583cc1c2414
      34:     0x562355804cad - core::ops::function::FnOnce::call_once{{vtable.shim}}::h0d99182cc1cda66c
      35:     0x5623558a7435 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha99802c2c52ada61
                                   at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/alloc/src/boxed.rs:1861:9
      36:     0x5623558a7435 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha39aea1c57e28a15
                                   at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/alloc/src/boxed.rs:1861:9
      37:     0x5623558a7435 - std::sys::unix::thread::Thread::new::thread_start::h9f8e3d72b1f7662f
                                   at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/sys/unix/thread.rs:108:17
      38:     0x7fec1b9f08fd - <unknown>
      39:     0x7fec1ba72a60 - <unknown>
      40:                0x0 - <unknown>
    
    opened by lincheney 3
  • Can't compile problem

    Can't compile problem

    OS: Arch Linux on Windows 10 x86_64
    Kernel: 5.10.16.3-microsoft-standard-WSL2 Log:

    ❯ cargo install --git=https://github.com/rhysd/hgrep
        Updating git repository `https://github.com/rhysd/hgrep`
      Installing hgrep v0.1.3 (https://github.com/rhysd/hgrep#37082f52)
        Updating `sjtu` index
       Compiling libc v0.2.104
       Compiling autocfg v1.0.1
       Compiling cfg-if v1.0.0
       Compiling memchr v2.4.1
       Compiling proc-macro2 v1.0.30
       Compiling lazy_static v1.4.0
       Compiling unicode-xid v0.2.2
       Compiling syn v1.0.80
       Compiling pkg-config v0.3.20
       Compiling serde_derive v1.0.130
       Compiling log v0.4.14
       Compiling regex-syntax v0.6.25
       Compiling serde v1.0.130
       Compiling crossbeam-utils v0.8.5
       Compiling encoding_index_tests v0.1.4
       Compiling regex-automata v0.1.10
       Compiling hashbrown v0.11.2
       Compiling proc-macro-hack v0.5.19
       Compiling once_cell v1.8.0
       Compiling same-file v1.0.6
       Compiling crc32fast v1.2.1
       Compiling crossbeam-epoch v0.9.5
       Compiling fnv v1.0.7
       Compiling ryu v1.0.5
       Compiling bitflags v1.3.2
       Compiling termcolor v1.1.2
       Compiling ucd-trie v0.1.3
       Compiling safemem v0.3.3
       Compiling encoding_rs v0.8.29
       Compiling adler v1.0.2
       Compiling linked-hash-map v0.5.4
       Compiling rayon-core v1.9.1
       Compiling scopeguard v1.1.0
       Compiling serde_json v1.0.68
       Compiling version_check v0.9.3
       Compiling xml-rs v0.8.4
       Compiling bugreport v0.4.1
       Compiling base64 v0.13.0
       Compiling unicode-width v0.1.9
       Compiling itoa v0.4.8
       Compiling dtoa v0.4.8
       Compiling strsim v0.10.0
       Compiling std_prelude v0.2.12
       Compiling anyhow v1.0.44
       Compiling lazycell v1.3.0
       Compiling textwrap v0.14.2
       Compiling shell-escape v0.1.5
       Compiling bat v0.18.3
       Compiling bytecount v0.6.2
       Compiling either v1.6.1
       Compiling ansi_term v0.12.1
       Compiling indexmap v1.7.0
       Compiling num-traits v0.2.14
       Compiling memoffset v0.6.4
       Compiling num-integer v0.1.44
       Compiling miniz_oxide v0.4.4
       Compiling rayon v1.5.1
       Compiling encoding-index-simpchinese v1.20141219.5
       Compiling encoding-index-korean v1.20141219.5
       Compiling encoding-index-singlebyte v1.20141219.5
       Compiling encoding-index-japanese v1.20141219.5
       Compiling encoding-index-tradchinese v1.20141219.5
       Compiling thread_local v1.1.3
       Compiling walkdir v2.3.2
       Compiling pest v2.1.3
       Compiling line-wrap v0.1.1
       Compiling yaml-rust v0.4.5
       Compiling error-chain v0.12.4
       Compiling path_abs v0.5.1
       Compiling encoding v0.2.33
       Compiling semver-parser v0.10.2
       Compiling aho-corasick v0.7.18
       Compiling bstr v0.2.17
       Compiling grep-matcher v0.1.5
       Compiling os_str_bytes v4.2.0
       Compiling content_inspector v0.2.4
       Compiling atty v0.2.14
       Compiling terminal_size v0.1.17
       Compiling num_cpus v1.13.0
       Compiling memmap2 v0.3.1
       Compiling quote v1.0.10
       Compiling jobserver v0.1.24
       Compiling crossbeam-channel v0.5.1
       Compiling semver v0.11.0
       Compiling encoding_rs_io v0.1.7
       Compiling flate2 v1.0.22
       Compiling regex v1.5.4
       Compiling clap v3.0.0-beta.5
       Compiling cc v1.0.71
       Compiling grep-searcher v0.1.8
       Compiling crossbeam-deque v0.8.1
       Compiling chrono v0.4.19
       Compiling globset v0.4.8
       Compiling console v0.14.1
       Compiling grep-regex v0.1.9
       Compiling console v0.15.0
       Compiling clap_generate v3.0.0-beta.5
       Compiling sys-info v0.9.0
       Compiling onig_sys v69.7.1
       Compiling pcre2-sys v0.2.5
       Compiling ansi_colours v1.0.4
       Compiling git-version-macro v0.3.5
       Compiling grep-cli v0.1.6
       Compiling ignore v0.4.18
       Compiling git-version v0.3.5
       Compiling pcre2 v0.2.3
       Compiling grep-pcre2 v0.1.5
       Compiling bincode v1.3.3
       Compiling plist v1.2.1
       Compiling serde_yaml v0.8.21
       Compiling clircle v0.3.0
       Compiling onig v6.3.0
       Compiling syntect v4.6.0
       Compiling hgrep v0.1.3 (/home/young/.cargo/git/checkouts/hgrep-76d18114b713642b/37082f5)
    error[E0599]: no variant or associated item named `ColoredHelp` found for enum `AppSettings` in the current scope
      --> src/main.rs:22:38
       |
    22 |         .global_setting(AppSettings::ColoredHelp)
       |                                      ^^^^^^^^^^^ variant or associated item not found in `AppSettings`
    
    error[E0061]: this function takes 4 arguments but 3 arguments were supplied
       --> src/main.rs:242:19
        |
    242 |         "bash" => generate::<Bash, _>(&mut app, "hgrep", &mut stdout),
        |                   ^^^^^^^^^^^^^^^^^^^ --------  -------  ----------- supplied 3 arguments
        |                   |
        |                   expected 4 arguments
        |
    note: function defined here
       --> /home/young/.cargo/registry/src/mirrors.sjtug.sjtu.edu.cn-7a04d2510079875b/clap_generate-3.0.0-beta.5/src/lib.rs:239:8
        |
    239 | pub fn generate<G, S>(gen: G, app: &mut clap::App, bin_name: S, buf: &mut dyn Write)
        |        ^^^^^^^^
    
    error[E0061]: this function takes 4 arguments but 3 arguments were supplied
       --> src/main.rs:243:18
        |
    243 |         "zsh" => generate::<Zsh, _>(&mut app, "hgrep", &mut stdout),
        |                  ^^^^^^^^^^^^^^^^^^ --------  -------  ----------- supplied 3 arguments
        |                  |
        |                  expected 4 arguments
        |
    note: function defined here
       --> /home/young/.cargo/registry/src/mirrors.sjtug.sjtu.edu.cn-7a04d2510079875b/clap_generate-3.0.0-beta.5/src/lib.rs:239:8
        |
    239 | pub fn generate<G, S>(gen: G, app: &mut clap::App, bin_name: S, buf: &mut dyn Write)
        |        ^^^^^^^^
    
    error[E0061]: this function takes 4 arguments but 3 arguments were supplied
       --> src/main.rs:244:25
        |
    244 |         "powershell" => generate::<PowerShell, _>(&mut app, "hgrep", &mut stdout),
        |                         ^^^^^^^^^^^^^^^^^^^^^^^^^ --------  -------  ----------- supplied 3 arguments
        |                         |
        |                         expected 4 arguments
        |
    note: function defined here
       --> /home/young/.cargo/registry/src/mirrors.sjtug.sjtu.edu.cn-7a04d2510079875b/clap_generate-3.0.0-beta.5/src/lib.rs:239:8
        |
    239 | pub fn generate<G, S>(gen: G, app: &mut clap::App, bin_name: S, buf: &mut dyn Write)
        |        ^^^^^^^^
    
    error[E0061]: this function takes 4 arguments but 3 arguments were supplied
       --> src/main.rs:245:19
        |
    245 |         "fish" => generate::<Fish, _>(&mut app, "hgrep", &mut stdout),
        |                   ^^^^^^^^^^^^^^^^^^^ --------  -------  ----------- supplied 3 arguments
        |                   |
        |                   expected 4 arguments
        |
    note: function defined here
       --> /home/young/.cargo/registry/src/mirrors.sjtug.sjtu.edu.cn-7a04d2510079875b/clap_generate-3.0.0-beta.5/src/lib.rs:239:8
        |
    239 | pub fn generate<G, S>(gen: G, app: &mut clap::App, bin_name: S, buf: &mut dyn Write)
        |        ^^^^^^^^
    
    error[E0061]: this function takes 4 arguments but 3 arguments were supplied
       --> src/main.rs:246:21
        |
    246 |         "elvish" => generate::<Elvish, _>(&mut app, "hgrep", &mut stdout),
        |                     ^^^^^^^^^^^^^^^^^^^^^ --------  -------  ----------- supplied 3 arguments
        |                     |
        |                     expected 4 arguments
        |
    note: function defined here
       --> /home/young/.cargo/registry/src/mirrors.sjtug.sjtu.edu.cn-7a04d2510079875b/clap_generate-3.0.0-beta.5/src/lib.rs:239:8
        |
    239 | pub fn generate<G, S>(gen: G, app: &mut clap::App, bin_name: S, buf: &mut dyn Write)
        |        ^^^^^^^^
    
    Some errors have detailed explanations: E0061, E0599.
    For more information about an error, try `rustc --explain E0061`.
    error: failed to compile `hgrep v0.1.3 (https://github.com/rhysd/hgrep#37082f52)`, intermediate artifacts can be found at `/tmp/cargo-installWmUcTi`
    
    Caused by:
      could not compile `hgrep` due to 6 previous errors
    
    bug 
    opened by younger-1 2
  • Fix typos

    Fix typos

    Found via codespell -S target -L crate,fo

    Not sure if you want to update accross -> across?

    $ typos --format brief
    ./CHANGELOG.md:56:100: `Matrial` -> `Martial`
    ./testdata/syntect/wrap_region_jp_accross_line.out:15: `accross` -> `across`
    ./testdata/syntect/wrap_whole_3_lines.rs:3:31: `fo` -> `of`, `for`
    ./testdata/syntect/wrap_regions_japanese.rs:4:50: `fo` -> `of`, `for`
    ./testdata/syntect/wrap_region_accross_line.rs:12: `accross` -> `across`
    ./testdata/syntect/wrap_region_accross_line.out:12: `accross` -> `across`
    ./testdata/syntect/wrap_region_jp_accross_line.rs:15: `accross` -> `across`
    ./testdata/syntect/wrap_whole_3_lines.out:6:137: `fo` -> `of`, `for`
    ./testdata/syntect/wrap_accross_regions.out:5: `accross` -> `across`
    ./testdata/syntect/wrap_accross_regions.rs:5: `accross` -> `across`
    ./testdata/syntect/wrap_regions_japanese.out:8:356: `fo` -> `of`, `for`
    ./src/ripgrep.rs:942:15: `accross` -> `across`
    ./src/ripgrep.rs:947:16: `accross` -> `across`
    ./src/syntect.rs:1403:22: `accross` -> `across`
    ./src/syntect.rs:1405:29: `accross` -> `across`
    ./src/syntect.rs:1406:32: `accross` -> `across`
    
    opened by kianmeng 1
  • Support `--sort` option

    Support `--sort` option

    rg provides --sort option. hgrep also can support it.

    Note that using --sort option can slow hgrep because sorting the matches means all matches must be calculated before printing them. For example, when a pattern matches to very last of large file, calculating highlights generally requires long time (since highlight must be calculated from the start of file).

    enhancement 
    opened by rhysd 0
  • Indent guide

    Indent guide

    Consider to add indent guide to the result snippets. Since snippets usually include indents and sometimes the indent level is deep, it would be helpful to know the level.

        ┊   match self.regions.first().copied() {
        ┊   ┊   Some((s, e)) if o == s && o < e => RegionBoundary::Start,
        ┊   ┊   Some((_, e)) if o == e => {
        ┊   ┊   ┊   // When the next region is adjcent, skip changing highlight
        ┊   ┊   ┊   match self.regions.get(1) {
        ┊   ┊   ┊   ┊   Some((s, _)) if o == *s => RegionBoundary::NotFound,
        ┊   ┊   ┊   ┊   _ => RegionBoundary::End,
        ┊   ┊   ┊   }
        ┊   ┊   }
        ┊   ┊   _ => RegionBoundary::NotFound,
        ┊   }
    
    • Character: (U+250A)
    • Color: gutter
    • Option: --no-indent-guide (indent guide is enabled by default)

    Note that this feature is automatically disabled by --ascii-lines.

    Challenges:

    • How to calculate indent width?
      • Width would be calculated at making chunks from grep matches.
    • How to handle tab character?
    • How to propagate the calculated indent width to a printer?

    I should to confirm that the guides are not so noisy in outputs before implementing this by crafting an example output.

    enhancement 
    opened by rhysd 0
Releases(v0.2.7)
Owner
Linda_pp
A dog enjoying software development (with bugs)
Linda_pp
A syntax-highlighting pager for git, diff, and grep output

Get Started Install delta and add this to your ~/.gitconfig: [core] pager = delta [interactive] diffFilter = delta --color-only [delta]

Dan Davison 16k Dec 31, 2022
This is choose, a human-friendly and fast alternative to cut and (sometimes) awk

Choose This is choose, a human-friendly and fast alternative to cut and (sometimes) awk Features terse field selection syntax similar to Python's list

Ryan Geary 1.4k Jan 7, 2023
A simple, human-friendly, embeddable scripting language

Mica Language reference · Rust API A simple, human-friendly scripting language, developed one feature at a time. Human-friendly syntax inspired by Rub

Mica programming language 32 Dec 30, 2022
Like grep, but uses tree-sitter grammars to search

tree-grepper Works like grep, but uses tree-sitter to search for structure instead of strings. Installing This isn't available packaged anywhere. That

Brian Hicks 219 Dec 25, 2022
Codemod - Codemod is a tool/library to assist you with large-scale codebase refactors that can be partially automated but still require human oversight and occasional intervention

Codemod - Codemod is a tool/library to assist you with large-scale codebase refactors that can be partially automated but still require human oversight and occasional intervention. Codemod was developed at Facebook and released as open source.

Meta Archive 4k Dec 29, 2022
Fuzzy Index for Python, written in Rust. Works like error-tolerant dict, keyed by a human input.

FuzzDex FuzzDex is a fast Python library, written in Rust. It implements an in-memory fuzzy index that works like an error-tolerant dictionary keyed b

Tomasz bla Fortuna 8 Dec 15, 2022
Human numeric sorting program — does what `sort -h` is supposed to do!

hns — Human Numeric Sort v0.1.0 (⏫︎2022-09-20) © 2022 Fredrick R. Brennan and hns Authors Apache 2.0 licensed, see LICENSE. man page Packages hns_0.1.

Fredrick Brennan 7 Sep 25, 2022
Display file sizes in human-readable units

hsize Display file sizes in human-readable units $ hsize 1000 1000000 5000000 1.00 KB 1.00 MB 5.00 MB $ hsize -p 5 1048576 12345678 1.04858 MB 12.345

Ryan 2 Nov 21, 2022
Experimental extension that brings OpenAI API to your PostgreSQL to run queries in human language.

Postgres <> ChatGPT Experimental PostgreSQL extension that enables the use of OpenAI GPT API inside PostgreSQL, allowing for queries to be written usi

CloudQuery 315 Apr 10, 2023
Baby's first Rust CLI project. Basic implementation of grep. Written in about 100 SLOC.

minigrep Coding project from Chapter 12 of the The Rust Programming Language book. Usage Compile and run as so minigrep QUERY FILENAME QUERY being the

Anis 2 Oct 2, 2021
A simplified recreation of the command-line utility grep written in Rust.

smolgrep A simplified recreation of the command-line utility grep written in Rust. Download and run Download Rust On Mac/Linux Open a terminal and ent

Thi Dinh 0 Dec 27, 2021
Fgr - Find & Grep utility with SQL-like query language

fgr Find & Grep utility with SQL-like query language. Examples # Find all files with name equal to sample under the current directory: fgr -e name=sam

Igor 3 Dec 22, 2022
Command-line tool that provides a workflow for extending, editing, diffing, and writing to vim-style grep lines.

Grug Grug is a command-line tool that provides a workflow for expanding, editing, diffing, and writing edits to files using vim-styled grep lines (suc

null 4 Apr 25, 2023
GREP like cli tool written in rust.

Show [ grep,tail,cat ] like cli tool written in rust. Only one release as of now which does very basic function,code has been refactored where other f

Siri 4 Jul 24, 2023
Cross-platform Rust library for coloring and formatting terminal output

Coloring terminal output Documentation term-painter is a cross-platform (i.e. also non-ANSI terminals) Rust library for coloring and formatting termin

Lukas Kalbertodt 75 Jul 28, 2022
A cargo plugin to shrink cargo's output

cargo single-line A simple cargo plugin that shrinks the visible cargo output to a single line (okay, in the best case scenario). In principle, the pl

Denis 5 Oct 30, 2022
A silly program written in Rust to output nonsensical sentences in the command line interface.

A silly program written in Rust to output nonsensical sentences in the command line interface.

Rachael Ava 1 Dec 13, 2021
Watch output and trigger on diff!

watchdiff Watch output and trigger on diff! Ever want to have watch output only tell you what changed? And not only what, but when? Now you can! Enter

geno 2 Apr 6, 2022
A cargo subcommand that displays ghidra function output through the use of the rizin rz-ghidra project.

cargo-rz-ghidra A cargo subcommand that displays ghidra function output through the use of the rizin rz-ghidra project. Install cargo install --git ht

wcampbell 4 Nov 5, 2022