caracall

Crates.iocaracall
lib.rscaracall
version0.1.1-1
sourcesrc
created_at2023-07-25 07:34:17.085857
updated_at2023-07-25 11:34:47.721728
descriptionA CLI utility that runs a shell command based on another command's output
homepage
repositoryhttps://gitlab.com/angel-val/caracall/
max_upload_size
id925252
size14,505
(iam-angel-val)

documentation

README

Caracall

A CLI utility that runs a shell command based on another command's output.

Keep in mind it keeps the output from the command you're checking against as well as any commands that it runs on success or error.

Also keep in mind this only works on linux :)

From caracall -h:

Usage: caracall [OPTIONS] <RUN>

Arguments:
  <RUN>  Command that is run and checked against

Options:
  -e <ON_ERROR>        Command that is run on stderr
  -s <ON_SUCCESS>      Command that is run on no stderr
  -l <LOOK_FOR>        Extra string to look for
  -f <ON_FIND>         Command that is run if that string is found
  -h, --help           Print help
  -V, --version        Print version

Install

Install cargo, and run cargo install caracall. Make sure the cargo binary path is also in your PATH.

Examples

A basic showcase of functionality:

# Echo something if grep doesn't find a file, echo something else if it does
# Also echo a third thing if it finds what you're grepping for
caracall "grep 'kitty' example.txt" \
    -s "echo 'found the file!'" \
    -e "echo 'didn't find the file!'" \
    -l "kitty" -f "echo 'found a kitty :3'"

Or a more practical example (this is what I made caracall for):

# Sends a notification to ntfy if a snapraid sync fails.
# Open https://ntfy.sh/example and run this command, and a notification should be sent
# (Assuming you don't already have snapraid setup on your machine lol)
caracall "snapraid sync" \
    -e "curl -d 'snapraid sync failed!' ntfy.sh/example"
Commit count: 6

cargo fmt