Skip to content

Commit

Permalink
Get rid of cleanup, only use TMP_FILE in listall.
Browse files Browse the repository at this point in the history
After the recent refactorings, the temporary file is only needed for the listall action. Therefore, the creation-checks and eventual cleanup can be restricted to the listall action, which should slightly speed up the overall script execution.
  • Loading branch information
inkarkat authored and ginatrapani committed Feb 15, 2012
1 parent 7485836 commit c8da8a6
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions todo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,6 @@ die()
exit 1
}

cleanup()
{
[ -f "$TMP_FILE" ] && rm "$TMP_FILE"
return 0
}

cleaninput()
{
# Parameters: When $1 = "for sed", performs additional escaping for use
Expand Down Expand Up @@ -670,7 +664,6 @@ ACTION=${1:-$TODOTXT_DEFAULT_ACTION}
[ -d "$TODO_DIR" ] || die "Fatal Error: $TODO_DIR is not a directory"
( cd "$TODO_DIR" ) || die "Fatal Error: Unable to cd to $TODO_DIR"

[ -w "$TMP_FILE" ] || echo -n > "$TMP_FILE" || die "Fatal Error: Unable to write to $TMP_FILE"
[ -f "$TODO_FILE" ] || cp /dev/null "$TODO_FILE"
[ -f "$DONE_FILE" ] || cp /dev/null "$DONE_FILE"
[ -f "$REPORT_FILE" ] || cp /dev/null "$REPORT_FILE"
Expand Down Expand Up @@ -854,9 +847,7 @@ then
elif [ -d "$TODO_ACTIONS_DIR" -a -x "$TODO_ACTIONS_DIR/$action" ]
then
"$TODO_ACTIONS_DIR/$action" "$@"
status=$?
cleanup
exit $status
exit $?
fi

## Only run if $action isn't found in .todo.actions.d
Expand Down Expand Up @@ -1082,12 +1073,15 @@ case $action in
"listall" | "lsa" )
shift ## Was lsa; new $1 is first search term

[ -w "$TMP_FILE" ] || echo -n > "$TMP_FILE" || die "Fatal Error: Unable to write to $TMP_FILE"
cat "$TODO_FILE" "$DONE_FILE" > "$TMP_FILE"
TOTAL=$( sed -n '$ =' "$TODO_FILE" )

post_filter_command="awk -v TOTAL=$TOTAL -v PADDING=${#TOTAL} '{ \$1 = sprintf(\"%\" PADDING \"d\", (\$1 > TOTAL ? 0 : \$1)); print }' "
TODOTXT_VERBOSE=0 _list "$TMP_FILE" "$@"

[ -f "$TMP_FILE" ] && rm "$TMP_FILE"

if [ $TODOTXT_VERBOSE -gt 0 ]; then
TDONE=$( sed -n '$ =' "$DONE_FILE" )
TASKNUM=$(TODOTXT_PLAIN=1 TODOTXT_VERBOSE=0 _list "$TODO_FILE" "$@" | sed -n '$ =')
Expand Down Expand Up @@ -1283,5 +1277,3 @@ note: PRIORITY must be anywhere from A to Z."
* )
usage;;
esac

cleanup

0 comments on commit c8da8a6

Please sign in to comment.