X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=logq-function;h=2ae5dae47fb8ff3e14890e34760473b220837b47;hb=d05b05db1c99982622ee70186c02d54f7d5cb5f9;hp=d07cba078045114da6555a5d7c7e96146d00e9e5;hpb=056b2e4c6d5fb9a3485279ec28cf93f2e34fc738;p=log-quiet diff --git a/logq-function b/logq-function old mode 100755 new mode 100644 index d07cba0..2ae5dae --- a/logq-function +++ b/logq-function @@ -13,56 +13,56 @@ # See the License for the specific language governing permissions and # limitations under the License. logq () { - local help="Usage: logq [-h|--help] COMMAND [ARG...] + local help="Usage: logq [-h|--help] COMMAND [ARG...] Log Quietly. Run COMMAND with ARGs, log to temp file. 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 }