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.
- 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.
The basic syntax to run fred is:
lua fred.lua <file> ["search_term"] [options]<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.
| 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. |
Consider the file test.md as an example.
If no search term is provided, fred will work similarly to cat, displaying the entire file content.
lua fred.lua test.mdTo find all lines containing the word "ipsum":
lua fred.lua test.md "ipsum"To find the word "ipsum" and highlight it in yellow:
lua fred.lua test.md "ipsum" -c yellowTo find the phrase "Donec dolor" and show which line it appears on:
lua fred.lua test.md "Donec dolor" -vExpected output:
Found occurrence on line 25: Donec dolor est, venenatis vel fermentum eget, auctor sed risus.
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 -vThe following colors are supported by the -c flag:
redgreenyellowbluemagenta
fred is available under the MIT License