Use sed line counting to replace 'wc -l'

This commit is contained in:
Ed Blackman
2009-03-14 01:15:52 -04:00
parent 6be78ca5fa
commit ab78607506

23
todo.sh
View File

@@ -392,7 +392,7 @@ _list() {
## Figure out how much padding we need to use ## Figure out how much padding we need to use
## We need one level of padding for each power of 10 $LINES uses ## We need one level of padding for each power of 10 $LINES uses
LINES=$( wc -l "$src" | sed 's/ .*//' ) LINES=$( sed -ne '$ =' < "$src" )
PADDING=${#LINES} PADDING=${#LINES}
## Number, sort, and mangle the file, then run the filter command, ## Number, sort, and mangle the file, then run the filter command,
@@ -427,9 +427,10 @@ _list() {
echo -e "$command" echo -e "$command"
if [ $TODOTXT_VERBOSE == 1 ]; then if [ $TODOTXT_VERBOSE == 1 ]; then
NUMTASKS=$( echo -e "$command" | wc -l | sed 's/ .*//' ) NUMTASKS=$( echo -e "$command" | sed -ne '/^$/d' -e '$ =' )
echo "--" echo "--"
echo "TODO: $NUMTASKS of $LINES tasks shown from $FILE" echo "TODO: ${NUMTASKS:-0} of $LINES tasks shown from $FILE"
fi fi
} }
@@ -471,7 +472,7 @@ case $action in
input="$now $input" input="$now $input"
fi fi
echo "$input" >> "$TODO_FILE" echo "$input" >> "$TODO_FILE"
TASKNUM=$(wc -l "$TODO_FILE" | sed 's/^[[:space:]]*\([0-9]*\).*/\1/') TASKNUM=$(sed -ne "$ =" < "$TODO_FILE")
[[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: '$input' added on line $TASKNUM." [[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: '$input' added on line $TASKNUM."
cleanup;; cleanup;;
@@ -485,7 +486,7 @@ case $action in
if [ -f "$dest" ]; then if [ -f "$dest" ]; then
echo "$input" >> "$dest" echo "$input" >> "$dest"
TASKNUM=$(wc -l "$dest" | sed 's/^[[:space:]]*\([0-9]*\).*/\1/') TASKNUM=$(sed -ne "$ =" < "$dest")
[[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: '$input' added to $dest on line $TASKNUM." [[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: '$input' added to $dest on line $TASKNUM."
else else
echo "TODO: Destination file $dest does not exist." echo "TODO: Destination file $dest does not exist."
@@ -781,15 +782,15 @@ note: PRIORITY must be anywhere from A to Z."
sed '/^x /!d' "$TODO_FILE" >> "$DONE_FILE" sed '/^x /!d' "$TODO_FILE" >> "$DONE_FILE"
sed -i.bak '/^x /d' "$TODO_FILE" sed -i.bak '/^x /d' "$TODO_FILE"
NUMLINES=$(wc -l "$TODO_FILE" | sed 's/^[[:space:]]*\([0-9]*\).*/\1/') NUMLINES=$( sed -ne '$ =' < "$TODO_FILE" )
if [ $NUMLINES = "0" ]; then if [ ${NUMLINES:-0} = "0" ]; then
echo "datetime todos dones" >> "$REPORT_FILE" echo "datetime todos dones" >> "$REPORT_FILE"
fi fi
#now report #now report
TOTAL=$(cat "$TODO_FILE" | wc -l | sed 's/^[ \t]*//') TOTAL=$( sed -ne '$ =' < "$TODO_FILE" )
TDONE=$(cat "$DONE_FILE" | wc -l | sed 's/^[ \t]*//') TDONE=$( sed -ne '$ =' < "$DONE_FILE" )
TECHO=$(echo $(date +%Y-%m-%d-%T); echo ' '; echo $TOTAL; echo ' '; TECHO=$(echo $(date +%Y-%m-%d-%T); echo ' '; echo ${TOTAL:-0}; echo ' ';
echo $TDONE) echo ${TDONE:-0})
echo $TECHO >> "$REPORT_FILE" echo $TECHO >> "$REPORT_FILE"
[[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: Report file updated." [[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: Report file updated."
cat "$REPORT_FILE" cat "$REPORT_FILE"