Crates.io | ricat |
lib.rs | ricat |
version | 0.4.5 |
source | src |
created_at | 2024-03-12 21:00:11.425171 |
updated_at | 2024-05-20 17:48:00.95751 |
description | A Rust-Based implemenation of classic UNIX `cat` command |
homepage | |
repository | https://github.com/adityanav123/ricat |
max_upload_size | |
id | 1171004 |
size | 100,921 |
cat
Command ImplementationThis project is a Rust-based reimagining of the classic Unix cat
command, drawing inspiration from its original implementation in GNU Core Utilities. It demonstrates the power and flexibility of Rust for system utilities development.
ricat
ricat
is designed with flexibility in mind, making it a valuable tool in the command line toolkit. One of its powerful features is the ability to seamlessly integrate with the pipe |
operator, allowing users to pipe the output of any command directly into ricat for further processing. This means you can easily use ricat to view, modify, or extend the output of other commands in real-time. Whether it's adding line numbers, appending symbols to each line, or leveraging any of ricat's other features, integrating ricat into your command line workflows can significantly enhance your productivity and command line capabilities.
Ensure you have Rust and Cargo installed on your system. If you don't have Rust installed, you can install it from the official site.
You can install ricat
directly from crates.io by running:
cargo install ricat
This command installs the ricat
binary, making it available for use in your terminal
If you have ricat
already installed, you can update it by force installing the newer version over the older version:
cargo install ricat --force
-n
flag.$
sign at the end of each line using the -d
flag.^I
using the -t
flag.-s
flag.--search
and --text
flags.
--ignore-case
or -i
flag.reg:
. For example, ricat --search --text "reg:\\d+" my_file.txt
--encode-base64
flag.--decode-base64
flag.ricat
to be used in command pipelines.--pages
flag.These features make ricat
a versatile tool for text processing and manipulation, providing a range of functionalities to enhance your command-line workflows.
ricat my_file.txt
ricat my_file.txt -n
$
sign at the end of each Linericat -d my_file.txt
To read and concatenate the contents of multiple files, specify each file path separated by a space:
ricat file1.txt file2.txt file3.txt
For searching text within a file, use the --search
flag, along with the --text
flag to specify the text to search for.
To search for and return lines containing a specific pattern or word within a single file:
ricat --search --text "string_to_search" my_file.txt
For regular expression searches, ensure the pattern is a valid regex. For example, to find lines containing digits:
ricat --search --text "reg:\\d+" my_file.txt
For ignoring case sensitivity, use the --ignore-case
or -i
flag:
ricat --search --text "string_to_search" --ignore-case my_file.txt
ricat
to be used in a pipeline of commands, where it can receive input from a previous command and pass its output to the next command. Without any arguments, ricat
effectively acts as a simple text editor that displays what you type in real-time, making it useful for creating short text files directly from the command line by redirecting the output to a file using the > operator.ricat
ricat
df | ricat --search --text "/dev/nvme0"
This command will show the disk space usage for all the partitions of drive nvme0
ricat --encode-base64 message.txt
This will convert all the contents of message.txt via base-64 encoding
ricat --decode-base64 encoded_message.txt
This command will convert the contents of encoded_message.txt via base-64 decoding
echo -n "And" | base64 | ricat --decode-base64
Example of encoding and then decoding the string "And"
ricat
ricat --help
Config file for ricat is stored in $HOME/.config/ricat/ricat_cfg.toml. You can change the presets for the features in this file. The file is created when you run the ricat command for the first time.
Defaults:
number_feature = false
dollar_sign_feature = false
tabs_feature = false
compress_empty_line_feature = false
ricat
provides benchmark scripts to compare its performance with the standard cat and a previous version of ricat
already installed.
benchmark.sh
: Compares the execution time of current:ricat
, cat
and prev:ricat
for a single run with a specified memory size (default: 1GB)../benchmark.sh
benchmark_plot.sh
: Averages the execution time over multiple iterations (default: 10) and plots a comparision graph../benchmark_plot.sh <memory_size_in_MB>
Eg. ./benchmark_plot.sh 4096
These benchmarks scripts utilise memory-mapped I/O for improved performance when reading large files without applying any features.
ricat
To test the ricat
features, you can run the following command:
./test-ricat.sh
Run this command in the root of the project
Adding new features to ricat
is straightforward. Implement the LineTextFeature
trait for any struct to create a new feature. For example, to add a feature that highlights TODO comments in your text files, define a struct implementing LineTextFeature
that scans each line for the pattern and applies the desired formatting.
[x] Remove the need of -f
flag for reading the filename input
[x] Return all the lines with a given pattern/word.
[x] Feature: Adding Encoding and Decoding ability (base64
)
[ ] Non-UTF8 Support: To be Done. See Issue #18
[ ] Stand-in replacement for cat.
Contributions are most welcome! If you have ideas for new features or improvements, please feel free to submit a pull request or open an issue.
To report bugs, you can go to the GitHub Discussions
q
key.Added custom testing file for testing the ricat
features.
Fixed Bug with ricat
not working with the standard input mode: #21
-- To run the test cases, run ./test-ricat.sh in the root directory of the project.
reg:
prefix.--ignore-case
flag.--encode-base64
& --decode-base64
flags]ricat
without any file input was not applying feature on standard input mode.--pages
flag]^I
.