#shell #command-output #linux-command #run-command #command-line-tool #another #cli

app caracall

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

3 releases

0.1.1 Jul 25, 2023
0.1.0 Jul 25, 2023

#16 in #linux-command

GPL-3.0-or-later

7KB
77 lines

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"

Dependencies

~1.2–1.7MB
~33K SLoC