Browse Source

fix missing newline and add option handling and file io

master
Georg Hopp 8 years ago
parent
commit
5a966fc391
Signed by: ghopp GPG Key ID: 4C5D226768784538
  1. 105
      timesheet/timesheet.sh

105
timesheet/timesheet.sh

@ -57,7 +57,7 @@ function taskend() {
function taskuuids() { function taskuuids() {
local UUID local UUID
[[ $# -eq 0 ]] && set \( +PENDING or +DONE \)
[[ $# -eq 0 ]] && set -- \( +PENDING or +DONE \)
for UUID in $(task $@ _uuid) for UUID in $(task $@ _uuid)
do do
printf "%05.2f\037%s\037%s\n" \ printf "%05.2f\037%s\037%s\n" \
@ -113,7 +113,7 @@ function extracttime() {
TIME="00:00:00" TIME="00:00:00"
else else
IFS=: IFS=:
set $(echo $1)
set -- $(echo $1)
IFS=${OIFS} IFS=${OIFS}
TIMEKEY="$1" TIMEKEY="$1"
TIME=$(printf "%02d:%02d:%02d" ${2:-0} ${3:-0} $4) TIME=$(printf "%02d:%02d:%02d" ${2:-0} ${3:-0} $4)
@ -125,7 +125,7 @@ function printtimes() {
for T in "$@" for T in "$@"
do do
extracttime "$T" extracttime "$T"
printf "%51s: %s\n" "spent - $TIMEKEY" $TIME
printf "%51s: %s\n" "spent - $TIMEKEY" "$TIME"
done done
} }
@ -165,20 +165,29 @@ function showall() {
} }
function timesheet() { function timesheet() {
local phrase="1-week-ago"
local start="$(date +%Y-%m-%d -d ${phrase})"
local end="$(date +%Y-%m-%d)"
local PHRASE="1-week-ago"
local START="$(date +%Y-%m-%d -d ${PHRASE})"
local DONE="$(showall $(doneuuids end.after:${START} $@))"
local UPCOMING="$(showall $(pendinguuids $@))"
local BLOCKED="$(showall $(blockeduuids $@))"
local BLOCKING="$(showall $(blockinguuids $@))"
DONE="${DONE:+${DONE}${NL}}"
UPCOMING="${UPCOMING:+${UPCOMING}${NL}}"
BLOCKED="${BLOCKED:+${BLOCKED}${NL}}"
BLOCKING="${BLOCKING:+${BLOCKING}${NL}}"
printf " (generated at %s)\n\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n" \ printf " (generated at %s)\n\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n" \
"$(date)" \
"$(bold "" "Tasks completed from $start to $end (back $phrase)")" \
"$(showall $(doneuuids end.after:${start} $@))" \
"${TODAY}" \
"$(bold "" "Tasks completed from $START to $TODAY (back $PHRASE)")" \
"${DONE}" \
"$(bold "" "Upcoming tasks")" \ "$(bold "" "Upcoming tasks")" \
"$(showall $(pendinguuids $@))" \
"${UPCOMING}" \
"$(bold "" "Blocked tasks")" \ "$(bold "" "Blocked tasks")" \
"$(showall $(blockeduuids $@))" \
"${BLOCKED}" \
"$(bold "" "Blocking tasks")" \ "$(bold "" "Blocking tasks")" \
"$(showall $(blockinguuids $@))"
"${BLOCKING}"
printf "%s%s\n\n%s%s\n%s\n\n%s\n\n%s\n" \ printf "%s%s\n\n%s%s\n%s\n\n%s\n\n%s\n" \
"$(bold "" "Summary")" \ "$(bold "" "Summary")" \
@ -190,6 +199,78 @@ function timesheet() {
"$(task rc._forcecolor=on $@ burndown 2>/dev/null)" "$(task rc._forcecolor=on $@ burndown 2>/dev/null)"
} }
function usage() {
local USAGE=$(cat <<-USAGE
Usage: %s [OPTION]... [FILTER]
OPTIONS:
-?, --help Show this help
-h, --html Create HTML form ANSI data.
-f, --file The file to write data to. Actually this specifies the
basename which will be postfixed by the creation date.
FILTER can be additional taskwarriors filters to limit the result
any further.
USAGE
)
/usr/bin/printf "${USAGE}\n" $0
}
TODAY="$(date +%Y-%m-%d)"
NL=$'\n'
#
# parse command line arguments
#
SHORTOPTS=?hf:
LONGOPTS=help,html,file
ARGS=$(getopt -o "${SHORTOPTS}" --long "${LONGOPTS}" -n "timesheet" -- "$@")
if [ $? -ne 0 ]
then
usage "$0"
exit 1
fi
eval set -- "${ARGS}"
unset ARGS
while true
do
case "$1" in
'-?'|'--help')
shift
usage "$0"
exit 0
;;
'-h'|'--html')
DOHTML=1
shift
continue
;;
'-f'|'--file')
OUTFILE="${2}_$TODAY"
shift 2
continue
;;
'--')
shift
break
;;
*)
echo 'Internal error!' >&2
exit 1
;;
esac
done
[[ $OUTFILE ]] && {
if [[ ${DOHTML} -eq 1 ]]
then
exec 1> >(ansi2html >${OUTFILE}.html)
else
exec 1> ${OUTFILE}.ansi
fi
}
timesheet $@ timesheet $@
# vim: set et ts=4 sw=4: # vim: set et ts=4 sw=4:
Loading…
Cancel
Save