Refactoring: Moved cleanup() calls from individual actions to end of script.
This commit is contained in:
46
todo.sh
46
todo.sh
@@ -279,7 +279,6 @@ archive()
|
|||||||
sed -n 'G; s/\n/&&/; /^\([ ~-]*\n\).*\n\1/d; s/\n//; h; P' "$TMP_FILE" > "$TODO_FILE"
|
sed -n 'G; s/\n/&&/; /^\([ ~-]*\n\).*\n\1/d; s/\n//; h; P' "$TMP_FILE" > "$TODO_FILE"
|
||||||
#[[ $TODOTXT_VERBOSE -gt 0 ]] && echo "TODO: Duplicate tasks have been removed."
|
#[[ $TODOTXT_VERBOSE -gt 0 ]] && echo "TODO: Duplicate tasks have been removed."
|
||||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $TODO_FILE archived."
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $TODO_FILE archived."
|
||||||
cleanup
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -637,7 +636,7 @@ case $action in
|
|||||||
input=$*
|
input=$*
|
||||||
fi
|
fi
|
||||||
_addto "$TODO_FILE" "$input"
|
_addto "$TODO_FILE" "$input"
|
||||||
cleanup;;
|
;;
|
||||||
|
|
||||||
"addm")
|
"addm")
|
||||||
if [[ -z "$2" && $TODOTXT_FORCE = 0 ]]; then
|
if [[ -z "$2" && $TODOTXT_FORCE = 0 ]]; then
|
||||||
@@ -659,7 +658,7 @@ case $action in
|
|||||||
_addto "$TODO_FILE" "$line"
|
_addto "$TODO_FILE" "$line"
|
||||||
done
|
done
|
||||||
IFS=$SAVEIFS
|
IFS=$SAVEIFS
|
||||||
cleanup;;
|
;;
|
||||||
|
|
||||||
"addto" )
|
"addto" )
|
||||||
[ -z "$2" ] && die "usage: $TODO_SH addto DEST \"TODO ITEM\""
|
[ -z "$2" ] && die "usage: $TODO_SH addto DEST \"TODO ITEM\""
|
||||||
@@ -674,7 +673,7 @@ case $action in
|
|||||||
else
|
else
|
||||||
echo "TODO: Destination file $dest does not exist."
|
echo "TODO: Destination file $dest does not exist."
|
||||||
fi
|
fi
|
||||||
cleanup;;
|
;;
|
||||||
|
|
||||||
"append" | "app" )
|
"append" | "app" )
|
||||||
errmsg="usage: $TODO_SH append ITEM# \"TEXT TO APPEND\""
|
errmsg="usage: $TODO_SH append ITEM# \"TEXT TO APPEND\""
|
||||||
@@ -700,7 +699,7 @@ case $action in
|
|||||||
else
|
else
|
||||||
echo "TODO: Error appending task $item."
|
echo "TODO: Error appending task $item."
|
||||||
fi
|
fi
|
||||||
cleanup;;
|
;;
|
||||||
|
|
||||||
"archive" )
|
"archive" )
|
||||||
archive;;
|
archive;;
|
||||||
@@ -732,7 +731,6 @@ case $action in
|
|||||||
sed -i.bak -e $item"s/^.*//" "$TODO_FILE"
|
sed -i.bak -e $item"s/^.*//" "$TODO_FILE"
|
||||||
fi
|
fi
|
||||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$DELETEME' deleted."
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$DELETEME' deleted."
|
||||||
cleanup
|
|
||||||
else
|
else
|
||||||
echo "TODO: No tasks were deleted."
|
echo "TODO: No tasks were deleted."
|
||||||
fi
|
fi
|
||||||
@@ -742,7 +740,8 @@ case $action in
|
|||||||
else
|
else
|
||||||
sed -i.bak -e $item"s/$3/ /g" "$TODO_FILE"
|
sed -i.bak -e $item"s/$3/ /g" "$TODO_FILE"
|
||||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $3 removed from $item."
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $3 removed from $item."
|
||||||
fi ;;
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
"depri" | "dp" )
|
"depri" | "dp" )
|
||||||
errmsg="usage: $TODO_SH depri ITEM#[, ITEM#, ITEM#, ...]"
|
errmsg="usage: $TODO_SH depri ITEM#[, ITEM#, ITEM#, ...]"
|
||||||
@@ -770,7 +769,7 @@ case $action in
|
|||||||
die "$errmsg"
|
die "$errmsg"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
cleanup ;;
|
;;
|
||||||
|
|
||||||
"do" )
|
"do" )
|
||||||
errmsg="usage: $TODO_SH do ITEM#[, ITEM#, ITEM#, ...]"
|
errmsg="usage: $TODO_SH do ITEM#[, ITEM#, ITEM#, ...]"
|
||||||
@@ -806,7 +805,7 @@ case $action in
|
|||||||
if [ $TODOTXT_AUTO_ARCHIVE = 1 ]; then
|
if [ $TODOTXT_AUTO_ARCHIVE = 1 ]; then
|
||||||
archive
|
archive
|
||||||
fi
|
fi
|
||||||
cleanup ;;
|
;;
|
||||||
|
|
||||||
"help" )
|
"help" )
|
||||||
if [ -t 1 ] ; then # STDOUT is a TTY
|
if [ -t 1 ] ; then # STDOUT is a TTY
|
||||||
@@ -821,8 +820,6 @@ case $action in
|
|||||||
"list" | "ls" )
|
"list" | "ls" )
|
||||||
shift ## Was ls; new $1 is first search term
|
shift ## Was ls; new $1 is first search term
|
||||||
_list "$TODO_FILE" "$@"
|
_list "$TODO_FILE" "$@"
|
||||||
|
|
||||||
cleanup
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"listall" | "lsa" )
|
"listall" | "lsa" )
|
||||||
@@ -830,8 +827,6 @@ case $action in
|
|||||||
|
|
||||||
cat "$TODO_FILE" "$DONE_FILE" > "$TMP_FILE"
|
cat "$TODO_FILE" "$DONE_FILE" > "$TMP_FILE"
|
||||||
_list "$TMP_FILE" "$@"
|
_list "$TMP_FILE" "$@"
|
||||||
|
|
||||||
cleanup
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"listfile" | "lf" )
|
"listfile" | "lf" )
|
||||||
@@ -840,18 +835,15 @@ case $action in
|
|||||||
shift ## Was filename; next $1 is first search term
|
shift ## Was filename; next $1 is first search term
|
||||||
|
|
||||||
_list "$FILE" "$@"
|
_list "$FILE" "$@"
|
||||||
|
|
||||||
cleanup
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"listcon" | "lsc" )
|
"listcon" | "lsc" )
|
||||||
grep -o '[^ ]*@[^ ]\+' "$TODO_FILE" | grep '^@' | sort -u
|
grep -o '[^ ]*@[^ ]\+' "$TODO_FILE" | grep '^@' | sort -u
|
||||||
cleanup ;;
|
;;
|
||||||
|
|
||||||
"listproj" | "lsprj" )
|
"listproj" | "lsprj" )
|
||||||
grep -o '[^ ]*+[^ ]\+' "$TODO_FILE" | grep '^+' | sort -u
|
grep -o '[^ ]*+[^ ]\+' "$TODO_FILE" | grep '^+' | sort -u
|
||||||
cleanup ;;
|
;;
|
||||||
|
|
||||||
|
|
||||||
"listpri" | "lsp" )
|
"listpri" | "lsp" )
|
||||||
shift ## was "listpri", new $1 is priority to list
|
shift ## was "listpri", new $1 is priority to list
|
||||||
@@ -906,7 +898,6 @@ case $action in
|
|||||||
echo "$MOVEME" >> "$dest"
|
echo "$MOVEME" >> "$dest"
|
||||||
|
|
||||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$MOVEME' moved from '$src' to '$dest'."
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$MOVEME' moved from '$src' to '$dest'."
|
||||||
cleanup
|
|
||||||
else
|
else
|
||||||
echo "TODO: No tasks moved."
|
echo "TODO: No tasks moved."
|
||||||
fi
|
fi
|
||||||
@@ -919,7 +910,7 @@ case $action in
|
|||||||
else
|
else
|
||||||
echo "TODO: Source file $src does not exist."
|
echo "TODO: Source file $src does not exist."
|
||||||
fi
|
fi
|
||||||
cleanup;;
|
;;
|
||||||
|
|
||||||
"prepend" | "prep" )
|
"prepend" | "prep" )
|
||||||
errmsg="usage: $TODO_SH prepend ITEM# \"TEXT TO PREPEND\""
|
errmsg="usage: $TODO_SH prepend ITEM# \"TEXT TO PREPEND\""
|
||||||
@@ -965,7 +956,7 @@ case $action in
|
|||||||
echo "TODO: Error prepending task $item."
|
echo "TODO: Error prepending task $item."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
cleanup;;
|
;;
|
||||||
|
|
||||||
"pri" | "p" )
|
"pri" | "p" )
|
||||||
item=$2
|
item=$2
|
||||||
@@ -988,10 +979,10 @@ note: PRIORITY must be anywhere from A to Z."
|
|||||||
echo "$item: $NEWTODO"
|
echo "$item: $NEWTODO"
|
||||||
echo "TODO: $item prioritized ($newpri)."
|
echo "TODO: $item prioritized ($newpri)."
|
||||||
}
|
}
|
||||||
cleanup
|
|
||||||
else
|
else
|
||||||
die "$errmsg"
|
die "$errmsg"
|
||||||
fi;;
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
"replace" )
|
"replace" )
|
||||||
errmsg="usage: $TODO_SH replace ITEM# \"UPDATED ITEM\""
|
errmsg="usage: $TODO_SH replace ITEM# \"UPDATED ITEM\""
|
||||||
@@ -1028,7 +1019,7 @@ note: PRIORITY must be anywhere from A to Z."
|
|||||||
echo "replaced with"
|
echo "replaced with"
|
||||||
echo "$item: $NEWTODO"
|
echo "$item: $NEWTODO"
|
||||||
}
|
}
|
||||||
cleanup;;
|
;;
|
||||||
|
|
||||||
"report" )
|
"report" )
|
||||||
#archive first
|
#archive first
|
||||||
@@ -1047,9 +1038,10 @@ note: PRIORITY must be anywhere from A to Z."
|
|||||||
echo $TECHO >> "$REPORT_FILE"
|
echo $TECHO >> "$REPORT_FILE"
|
||||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: Report file updated."
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: Report file updated."
|
||||||
cat "$REPORT_FILE"
|
cat "$REPORT_FILE"
|
||||||
cleanup;;
|
;;
|
||||||
|
|
||||||
* )
|
* )
|
||||||
usage
|
usage;;
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
cleanup
|
||||||
|
|||||||
Reference in New Issue
Block a user