update README for gitorious move
[log-quiet] / logq
1 #!/bin/bash
2 logq () {
3 local help="Usage: logq [-h|--help] COMMAND [ARG...]
4
5 Log Quietly. Run COMMAND with ARGs, log to temp file. Output return code,
6 command, and log path.
7
8 Minor details: Use logsave if available, which adds informational header/footer
9 to log file. Logfile is put in random temp dir, with filename made from the
10 alphanumeric characters of COMMAND + ARGs."
11
12 if [[ $1 == --help || $1 == -h ]]; then
13 echo "$help"
14 return
15 fi
16 if [[ $# == 0 ]]; then
17 echo "error: need 1 or more arguments
18 $help"
19 return 1
20 fi
21
22 local index=0
23 local x prettycommand
24 for x in "$@"; do
25 prettycommand+="[$index]$x "
26 index=$(( index+1 ))
27 done
28
29
30 local file="$*"
31 file="$(mktemp -d)/${file//[^[:alnum:]]/}"
32
33 printf "%s\n%s\n\n" "log of $prettycommand" "$(date)" >"$file"
34
35 # we will propagate any errors
36 local e=$-
37 [[ $e == *e* ]] && set +e
38 "$@" &>> "$file"
39 local ret=$?
40 [[ $e == *e* ]] && set -e
41
42 printf "\n%s\n%s\n%s" "----------------" "$(date)" "end of log" >>"$file"
43
44 echo -n "\$?=$ret "
45 echo -n "$prettycommand"
46 echo "[log] $file"
47 return $ret
48 }
49 logq "$@"