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

app caracall

一个基于其他命令输出运行 shell 命令的 CLI 工具

3 个版本

0.1.1 2023 年 7 月 25 日
0.1.0 2023 年 7 月 25 日

#2642命令行工具

GPL-3.0-or-later

7KB
77

Caracall

一个基于其他命令输出运行 shell 命令的 CLI 工具。

请注意,它还保留了你正在检查的命令的输出以及它在成功或错误时运行的任何命令的输出。

请注意,这只能在 Linux 上工作 :)

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

安装

安装 cargo,并运行 cargo install caracall. 确保 cargo 二进制路径也已添加到您的 PATH。

示例

功能的基本展示

# 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'"

或一个更实用的例子(这是我制作 caracall 的原因)

# 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"

依赖项

~1.2–1.8MB
~33K SLoC