X-Git-Url: https://iankelling.org/git/?p=log-quiet;a=blobdiff_plain;f=logq;h=08b059d70048b0f834cdaa6c98350cef717613d0;hp=b253bef510416c8f9a256b2d2599d090ae81b27c;hb=ea9d543d812b5ec13d4d3c6b424626f3afaaa5dc;hpb=457661424027a87b9ea600cfeb218574e95470d4 diff --git a/logq b/logq index b253bef..08b059d 100755 --- a/logq +++ b/logq @@ -16,58 +16,58 @@ # This file is exactly the same as logq-function except the last line # to make it into a script. logq () { - local help="Usage: logq [-h|--help] COMMAND [ARG...] + local help="Usage: logq [-h|--help] COMMAND [ARG...] Log to temp file, output tail of log in case of error. Run COMMAND with ARGs. Output return code, command, and log path. Tail log if there is a failure. Follows output format of logsave." - if [[ $1 == --help || $1 == -h ]]; then - echo "$help" - return - fi - if [[ $# == 0 ]]; then - echo "error: need 1 or more arguments + if [[ $1 == --help || $1 == -h ]]; then + echo "$help" + return + fi + if [[ $# == 0 ]]; then + echo "error: need 1 or more arguments $help" - return 1 - fi + return 1 + fi - # deliniate arguments, so spaces aren't ambiguous - local index=0 - local x prettycommand - for x in "$@"; do - prettycommand+="[$index]$x " - index=$(( index+1 )) - done + # deliniate arguments, so spaces aren't ambiguous + local index=0 + local x prettycommand + for x in "$@"; do + prettycommand+="[$index]$x " + index=$(( index+1 )) + done - local file="$*" - file="$(mktemp -d)/${file//[[:space:]\/]/_}" - # give us ~20 char filename max - file="${file:0:40}" + local file="$*" + file="$(mktemp -d)/${file//[[:space:]\/]/_}" + # give us ~20 char filename max + file="${file:0:40}" - printf "%s\n%s\n\n" "Log of $prettycommand" "$(date)" >"$file" + printf "%s\n%s\n\n" "Log of $prettycommand" "$(date)" >"$file" - if [[ $- != *x* ]]; then - echo "log $file = $@" - fi + if [[ $- != *x* ]]; then + echo "log $file = $@" + fi - # we will propagate any errors - local logq_ret=$( - set +e - trap ERR - "$@" &>> "$file" - echo $? - ) - printf "\n%s\n%s\n" "$(date)" "----------------" >> "$file" + # we will propagate any errors + local logq_ret=$( + set +e + trap ERR + "$@" &>> "$file" + echo $? + ) + printf "\n%s\n%s\n" "$(date)" "----------------" >> "$file" - if [[ $logq_ret != 0 ]]; then - x="tail -n 100 $file" - if [[ $- != *x* ]]; then - echo "logq failure. $x :" - fi - $x + if [[ $logq_ret != 0 ]]; then + x="tail -n 100 $file" + if [[ $- != *x* ]]; then + echo "logq failure. $x :" fi - return $logq_ret + $x + fi + return $logq_ret } logq "$@"