GithubHelp home page GithubHelp logo

moot's Introduction

moot

Run a command but only show its output on error.

Examples

moot shows a summary instead of the command's normal output:

moot "Updating package repository" sudo apt-get update
Updating package repository ✓

If the command errors, the output will be shown:

moot "Installing windows-95" sudo apt-get install windows-95
Installing windows-95 ✗
$ sudo apt-get install windows-95
[0.0] Reading package lists...
[0.0] Building dependency tree...
[0.2] Reading state information...
{0.3} E: Unable to locate package windows-95
> exit: 100
> duration: 0.27s

You can run multiple commands by using a here document:

moot "Update and upgrade" <<'moot'
  sudo apt-get update
  sudo apt-get upgrade
moot
Update and upgrade ✓

Install

pip3 install --user moot

moot is also just a single file with no dependencies (apart from Python 3) so you can just download it directly:

wget -O /usr/local/bin/moot \
  https://raw.githubusercontent.com/vjagaro/moot/main/moot.py
chmod a+x /usr/local/bin/moot

Help

usage: moot [OPTIONS ...] SUMMARY [COMMAND ...]

Run COMMAND with its output suppressed and SUMMARY shown instead. If
COMMAND errors, then its output will be shown.

optional arguments:
  -h, --help           show this help message and exit
  -l FILE, --log FILE  additionally write output to FILE
  -a, --always-output  show output regardless of error state
  --no-color           suppress color
  --no-info            suppress info (command, exit code, duration)
  --no-timestamps      suppress timestamps

Advanced Techniques

When using moot with a here document to run multiple commands, you normally don't have access to functions and variables in the calling scope. With Bash, you can use the following helper function to get around this:

moot() {
  MOOT_SHELL_ENV="$(
    cat <(declare -p | grep -vE '^declare -(r|.r)') <(declare -fp) \
      <(echo "set -eou pipefail")
  )" command moot "$@"
}

Then, you can do things like:

MESSAGE="Hello!"

yell() {
  echo "$@" > "/tmp/message"
}

moot "Greetings" <<'moot'
  yell "$MESSAGE"
  yell "Again, $MESSAGE"
moot

moot's People

Contributors

vjagaro avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.