Thanks to visit codestin.com
Credit goes to github.com

Skip to content

cat and grep together and with steroids — display files and filter text patterns efficiently

License

Notifications You must be signed in to change notification settings

gdcmarinho/fred

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fred's Logo

GitHub License

fred is a simple program, inspired by cat and grep, to show files and search for text directly from your command line. It allows you to not only show content's file and find content but also highlight them with colors and display the corresponding line numbers.

Features

  • Text Search: Find lines containing a specific word or phrase.
  • Color Highlighting: Highlight the searched term with a color of your choice for easy viewing.
  • Line Numbering: Display the line number where each match was found.
  • Simplicity: A single script with no complex dependencies. Just have Lua installed.

Usage

The basic syntax to run fred is:

lua fred.lua <file> ["search_term"] [options]

Arguments

  • <file>: (Required) The path to the file you want to show the content.
  • ["search_term"]: (Optional) The word or phrase to search for. If it contains spaces, it must be enclosed in quotes.
  • [options]: (Optional) Flags to modify the search behavior.

Options

Flag Argument Description
-c <color> Highlights the found term with the specified color.
-v Displays the line number and the number of occurrences found on the line before the result.

Usage Examples

Consider the file test.md as an example.

1. Display the file content

If no search term is provided, fred will work similarly to cat, displaying the entire file content.

lua fred.lua test.md

2. Search for a word

To find all lines containing the word "ipsum":

lua fred.lua test.md "ipsum"

3. Search and highlight with color

To find the word "ipsum" and highlight it in yellow:

lua fred.lua test.md "ipsum" -c yellow

4. Search and display the line number

To find the phrase "Donec dolor" and show which line it appears on:

lua fred.lua test.md "Donec dolor" -v

Expected output:

Found occurrence on line 25: Donec dolor est, venenatis vel fermentum eget, auctor sed risus.

5. Combining options

You can combine flags for more detailed results. To search for "Mauris", highlight it in blue, and see the line numbers:

lua fred.lua test.md "Mauris" -c blue -v

Available Colors

The following colors are supported by the -c flag:

  • red
  • green
  • yellow
  • blue
  • magenta

License

fred is available under the MIT License

About

cat and grep together and with steroids — display files and filter text patterns efficiently

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages