#!/usr/bin/env bash colour_output=0 test -t 1 && colour_output=1 function bold() { if [[ $colour_output = 1 ]]; then printf "\x1B[1;33m$*\x1B[0m\n" else printf "$*\n" fi } function bold_err() { if [[ $colour_output = 1 ]]; then printf "\x1B[1;31m$*\x1B[0m\n" else printf "$*\n" fi } function succinct_output() { local in_err errprefix errloc errsuffix missing_string in_err=0 missing_string="$(bold_err '???')" errprefix="$missing_string" errloc="$missing_string" errsuffix="$missing_string" function output_reset() { if [[ $3 =~ due\ to\ .*previous\ error || $3 =~ ^Could\ not\ compile\ ]]; then return fi echo "$1: $2: $(bold "$3")" errprefix="$missing_string" errloc="$missing_string" errsuffix="$missing_string" } while IFS=$'\n' read line; do if [[ $line =~ ^(error|warning|help|note) ]]; then if [[ $in_err = 1 ]]; then output_reset "$errprefix" "$errloc" "$errsuffix" fi in_err=1 errprefix="$(cut -d: -f1 <<<"$line")" errsuffix="$(cut -d: -f2- <<<"$line" | cut -c 2-)" elif [[ $in_err = 1 && $line =~ ^[\ \t]*--\> ]]; then errloc="$(sed 's/^.*--> //' <<<"$line")" elif [[ $in_err = 1 && $line = "" ]]; then output_reset "$errprefix" "$errloc" "$errsuffix" in_err=0 elif [[ $in_err = 0 && $line != "To learn more, run the command again with --verbose." ]]; then echo "$line" fi done if [[ $in_err = 1 ]]; then output_reset "$errprefix" "$errloc" "$errsuffix" fi } cargo build "$@" 2>&1 | succinct_output