GithubHelp home page GithubHelp logo

gex's Introduction

gex - A Simple Grep Clone in Zig

gex is a small and efficient grep clone written in the Zig programming language. It provides basic text searching capabilities using both regular expressions (regex) and Zig's internal indexOf function from std.mem.

Features

  • Search for a specific pattern (needle) in a given text or file (haystack)
  • Support for regular expressions using the POSIX regex C library
  • Fast non-regex searching using Zig's indexOf function
  • Colorized output with ANSI color codes
  • Pipe support for searching within the output of other commands
  • Comparable performance to grep, with only a slight overhead of around 20ms in most use cases

Installation

To install gex, make sure you have Zig installed on your system. Then, follow these steps:

  1. Clone the gex repository:

    git clone https://github.com/claytoncasey01/gex.git

  2. Navigate to the gex directory:

    cd gex

  3. Build the project:

    zig build

  4. (Optional) Add the gex executable to your system's PATH for easier access.

Usage

Basic Usage

To search for a specific pattern (needle) in a given text or file (haystack), use the following command:

gex [needle] [haystack]

The haystack can be either input text or a file path.

Regular Expression Support

To enable regular expression searching (experimental), add the -R flag to the command:

gex [regex_pattern] [haystack] -R

Colorized Output

To enable colorized output using ANSI color codes, add the -c flag to the command:

gex -c [needle] [haystack]

Piping Support

gex supports piping, allowing you to search within the output of other commands. For example:

ls -l | gex zig

This command will search for the word "zig" within the output of the ls -l command.

Color Codes

gex supports all ANSI color codes through the -c flag. The available color codes are defined in the following enum:

pub const Color = enum(u8) {
  reset,
  black,
  red,
  green,
  yellow,
  blue,
  magenta,
  cyan,
  white,
  blackBright,
  redBright,
  greenBright,
  yellowBright,
  blueBright,
  magentaBright,
  cyanBright,
  whiteBright,
  // Background Colors
  bgBlack,
  bgRed,
  bgGreen,
  bgYellow,
  bgBlue,
  bgMagenta,
  bgCyan,
  bgWhite,
  bgBlackBright,
  bgRedBright,
  bgGreenBright,
  bgYellowBright,
  bgBlueBright,
  bgMagentaBright,
  bgCyanBright,
  bgWhiteBright,
};

Performance

gex aims to provide efficient searching capabilities. In most use cases, it is only slightly slower than grep, with a performance overhead of around 20ms or less. We are working on performance optimizations currently to either match or beat grep.

Contributing

Contributions to gex are welcome! If you find any bugs, have feature requests, or want to contribute improvements, please open an issue or submit a pull request on the GitHub repository.

License

gex is open-source software licensed under the MIT License.

gex's People

Contributors

claytoncasey01 avatar

Watchers

 avatar

gex's Issues

Output Formatting Options

Create a number of options to handle formatting output in various ways such as: match color, data included (line numbers, line, file name, etc), and standard vs structured output.

Colorize Memory Leak

Currently the colorizeWord function has a memory leak due to allocating a string and never actually freeing up that memory "I think". Look into fixing this, this function needs a refactor to use the standard lib better vs doing it all manually anyway.

Auto determine method

Currently in order to use a regex pattern it is required to pass the -R flag, this is not ideal. We should be able to determine if a given needle is a regex pattern or just a normal string and go down that code path.

Regex Support

To start we can use the POSIX regex library and do a small zig wrapper. Documentation can be found here

Unit test C code

Currently the testing and benchmarking process for the regex portion of the code can't be done (that I'm aware of currently) as easily as zig test since we have to link against libc and the c-code before running the tests. zig build test does link against libc and the regex c code now but the tests seem to hang.

Optimizations

Currently Gex is a bit slower than Grep, need to go through and optimize to get as close to standard Grep performance as possible.

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.