Fixing prepend and priority issue.
Check for priority, delete if found, prepend and add back priority. Uses awk and sed, works in linux.
This commit is contained in:
26
todo.sh
26
todo.sh
@@ -819,12 +819,28 @@ case $action in
|
|||||||
input=$*
|
input=$*
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if sed -i.bak $item" s|^.*|$input &|" "$TODO_FILE"; then
|
# Test for then set priority
|
||||||
newtodo=$(sed "$item!d" "$TODO_FILE")
|
if [ `sed "$item!d" "$TODO_FILE"|grep -c "^(\\w)"` -eq 1 ]; then
|
||||||
|
priority=$(sed "$item!d" "$TODO_FILE" | awk -F '\\(|\\)' '{print $2}')
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If priority isn't set prepend
|
||||||
|
if [ -z $priority ]; then
|
||||||
|
if sed -i.bak $item" s|^.*|$input &|" "$TODO_FILE"; then
|
||||||
|
newtodo=$(sed "$item!d" "$TODO_FILE")
|
||||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $newtodo"
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $newtodo"
|
||||||
else
|
else
|
||||||
echo "TODO: Error prepending task $item."
|
echo "TODO: Error prepending task $item."
|
||||||
fi
|
fi
|
||||||
|
# If priority is set, remove priority, prepend and add back priority
|
||||||
|
else
|
||||||
|
if sed -i.bak -e "$item s/^(.) //" -e "$item s|^.*|\($priority\) $1 &|" "$TODO_FILE"; then
|
||||||
|
newtodo=$(sed "$item!d" "$TODO_FILE")
|
||||||
|
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $newtodo"
|
||||||
|
else
|
||||||
|
echo "TODO: Error prepending task $item."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
cleanup;;
|
cleanup;;
|
||||||
|
|
||||||
"pri" | "p" )
|
"pri" | "p" )
|
||||||
|
|||||||
Reference in New Issue
Block a user