forked from todotxt/todo.txt-cli
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patharchive
executable file
·31 lines (28 loc) · 992 Bytes
/
archive
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
action=$1
shift
[ "$action" = "usage" ] && {
echo " Customized archive:"
echo " archive KEYWORD"
echo " Moves done items containing KEYWORD from todo.txt to done.txt and removes blank lines."
echo " archive ITEM#"
echo " Moves done item number ITEM# and removes blank lines."
echo " Note that if KEYWORD is a number it is considered as an ITEM# number"
echo ""
exit
}
KEYWORD=$1
if [[ "$KEYWORD" =~ ^[0-9]+$ ]]; then
# we got an ITEM to archive
[ $TODOTXT_VERBOSE -gt 0 ] && sed "$KEYWORD!d" "$TODO_FILE"
sed "$KEYWORD!d" "$TODO_FILE" >> "$DONE_FILE"
sed -i.bak "${KEYWORD}d" "$TODO_FILE"
else
# we got a keyword, or nothing
[ $TODOTXT_VERBOSE -gt 0 ] && grep "^x .*$KEYWORD" "$TODO_FILE"
grep "^x .*$KEYWORD" "$TODO_FILE" >> "$DONE_FILE"
sed -i.bak "/^x .*$KEYWORD/d" "$TODO_FILE"
fi
[ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $TODO_FILE archived."
#defragment blank lines
sed -i.bak -e '/./!d' "$TODO_FILE"