Compare commits
12 Commits
archive/to
...
archive/bu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b131b3e2d0 | ||
|
|
d2af44d8d3 | ||
|
|
f8a6e5f8d6 | ||
|
|
388ae745af | ||
|
|
cb908bd454 | ||
|
|
55679d136f | ||
|
|
c0847b0b25 | ||
|
|
76fb1cb3ee | ||
|
|
ac090fa30b | ||
|
|
ea0e7c7b25 | ||
|
|
cd7d2f2fda | ||
|
|
395465b5f2 |
@@ -39,6 +39,24 @@ GARDEN: 2 added.
|
||||
GARDEN: 2 of 2 tasks shown
|
||||
EOF
|
||||
|
||||
#
|
||||
# List available files
|
||||
#
|
||||
test_todo_session 'list available files' <<EOF
|
||||
>>> todo.sh listfile
|
||||
Files in the todo.txt directory:
|
||||
done.txt
|
||||
garden.txt
|
||||
report.txt
|
||||
todo.txt
|
||||
|
||||
>>> TODOTXT_VERBOSE=0 todo.sh listfile
|
||||
done.txt
|
||||
garden.txt
|
||||
report.txt
|
||||
todo.txt
|
||||
EOF
|
||||
|
||||
#
|
||||
# Filter
|
||||
#
|
||||
|
||||
@@ -66,6 +66,12 @@ TODO: 4 added.
|
||||
TODO: 4 of 4 tasks shown
|
||||
EOF
|
||||
|
||||
test_todo_session 'priority error' <<EOF
|
||||
>>> todo.sh pri 10 B
|
||||
=== 1
|
||||
TODO: No task 10.
|
||||
EOF
|
||||
|
||||
cat > todo.txt <<EOF
|
||||
(B) smell the uppercase Roses +flowers @outside
|
||||
(C) notice the sunflowers
|
||||
|
||||
@@ -53,6 +53,18 @@ test_todo_session 'checking TODOTXT_FINAL_FILTER' <<EOF
|
||||
TODO: 3 of 3 tasks shown
|
||||
EOF
|
||||
|
||||
#
|
||||
# check the custom hiding
|
||||
#
|
||||
test_todo_session 'checking HIDE_CUSTOM_SUBSTITUTION' <<EOF
|
||||
>>> HIDE_CUSTOM_SUBSTITUTION='[tT]h' todo.sh ls
|
||||
2 aaa zzz is line should be first.
|
||||
3 bbb yyy is line should be second.
|
||||
1 ccc xxx is line should be ird.
|
||||
--
|
||||
TODO: 3 of 3 tasks shown
|
||||
EOF
|
||||
|
||||
#
|
||||
# check the filtering of TERM
|
||||
#
|
||||
@@ -73,6 +85,29 @@ TODO: 1 of 3 tasks shown
|
||||
TODO: 1 of 3 tasks shown
|
||||
EOF
|
||||
|
||||
#
|
||||
# check negative filtering via -TERM
|
||||
#
|
||||
test_todo_session 'checking negative filtering via -TERM' <<EOF
|
||||
>>> todo.sh ls -second
|
||||
2 aaa zzz this line should be first.
|
||||
1 ccc xxx this line should be third.
|
||||
--
|
||||
TODO: 2 of 3 tasks shown
|
||||
|
||||
>>> todo.sh ls "-should be f"
|
||||
3 bbb yyy this line should be second.
|
||||
1 ccc xxx this line should be third.
|
||||
--
|
||||
TODO: 2 of 3 tasks shown
|
||||
|
||||
>>> todo.sh ls "- zzz"
|
||||
3 bbb yyy this line should be second.
|
||||
1 ccc xxx this line should be third.
|
||||
--
|
||||
TODO: 2 of 3 tasks shown
|
||||
EOF
|
||||
|
||||
#
|
||||
# check the filtering of TERM with regexp
|
||||
#
|
||||
|
||||
147
todo.sh
147
todo.sh
@@ -57,7 +57,7 @@ shorthelp()
|
||||
list|ls [TERM...]
|
||||
listall|lsa [TERM...]
|
||||
listcon|lsc
|
||||
listfile|lf SRC [TERM...]
|
||||
listfile|lf [SRC [TERM...]]
|
||||
listpri|lsp [PRIORITY] [TERM...]
|
||||
listproj|lsprj [TERM...]
|
||||
move|mv ITEM# DEST [SRC]
|
||||
@@ -211,11 +211,13 @@ help()
|
||||
lsc
|
||||
Lists all the task contexts that start with the @ sign in todo.txt.
|
||||
|
||||
listfile SRC [TERM...]
|
||||
lf SRC [TERM...]
|
||||
listfile [SRC [TERM...]]
|
||||
lf [SRC [TERM...]]
|
||||
Displays all the lines in SRC file located in the todo.txt directory,
|
||||
sorted by priority with line numbers. If TERM specified, lists
|
||||
all lines that contain TERM in SRC file.
|
||||
Without any arguments, the names of all text files in the todo.txt
|
||||
directory are listed.
|
||||
|
||||
listpri [PRIORITY] [TERM...]
|
||||
lsp [PRIORITY] [TERM...]
|
||||
@@ -294,6 +296,11 @@ cleanup()
|
||||
|
||||
cleaninput()
|
||||
{
|
||||
# Parameters: When $1 = "for sed", performs additional escaping for use
|
||||
# in sed substitution with "|" separators.
|
||||
# Precondition: $input contains text to be cleaned.
|
||||
# Postcondition: Modifies $input.
|
||||
|
||||
# Replace CR and LF with space; tasks always comprise a single line.
|
||||
input=${input//$'\r'/ }
|
||||
input=${input//$'\n'/ }
|
||||
@@ -308,6 +315,44 @@ cleaninput()
|
||||
fi
|
||||
}
|
||||
|
||||
getPrefix()
|
||||
{
|
||||
# Parameters: $1: todo file; empty means $TODO_FILE.
|
||||
# Returns: Uppercase FILE prefix to be used in place of "TODO:" where
|
||||
# a different todo file can be specified.
|
||||
local base=$(basename "${1:-$TODO_FILE}")
|
||||
echo "${base%%.[^.]*}" | tr 'a-z' 'A-Z'
|
||||
}
|
||||
|
||||
getTodo()
|
||||
{
|
||||
# Parameters: $1: task number
|
||||
# $2: Optional todo file
|
||||
# Precondition: $errmsg contains usage message.
|
||||
# Postcondition: $todo contains task text.
|
||||
|
||||
local item=$1
|
||||
[ -z "$item" ] && die "$errmsg"
|
||||
[ "${item//[0-9]/}" ] && die "$errmsg"
|
||||
|
||||
todo=$(sed "$item!d" "${2:-$TODO_FILE}")
|
||||
[ -z "$todo" ] && die "$(getPrefix "$2"): No task $item."
|
||||
}
|
||||
getNewtodo()
|
||||
{
|
||||
# Parameters: $1: task number
|
||||
# $2: Optional todo file
|
||||
# Precondition: None.
|
||||
# Postcondition: $newtodo contains task text.
|
||||
|
||||
local item=$1
|
||||
[ -z "$item" ] && die 'Programming error: $item should exist.'
|
||||
[ "${item//[0-9]/}" ] && die 'Programming error: $item should be numeric.'
|
||||
|
||||
newtodo=$(sed "$item!d" "${2:-$TODO_FILE}")
|
||||
[ -z "$newtodo" ] && die "$(getPrefix "$2"): No updated task $item."
|
||||
}
|
||||
|
||||
archive()
|
||||
{
|
||||
#defragment blank lines
|
||||
@@ -336,12 +381,7 @@ replaceOrPrepend()
|
||||
;;
|
||||
esac
|
||||
shift; item=$1; shift
|
||||
|
||||
[ -z "$item" ] && die "$errmsg"
|
||||
[[ "$item" = +([0-9]) ]] || die "$errmsg"
|
||||
|
||||
todo=$(sed "$item!d" "$TODO_FILE")
|
||||
[ -z "$todo" ] && die "TODO: No task $item."
|
||||
getTodo "$item"
|
||||
|
||||
if [[ -z "$1" && $TODOTXT_FORCE = 0 ]]; then
|
||||
echo -n "$querytext"
|
||||
@@ -366,7 +406,7 @@ replaceOrPrepend()
|
||||
# date again.
|
||||
sed -i.bak -e "$item s/^${priority}${prepdate}//" -e "$item s|^.*|${priority}${prepdate}${input}${backref}|" "$TODO_FILE"
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
newtodo=$(sed "$item!d" "$TODO_FILE")
|
||||
getNewtodo "$item"
|
||||
case "$action" in
|
||||
replace)
|
||||
echo "$item $todo"
|
||||
@@ -656,10 +696,8 @@ _addto() {
|
||||
echo "$input" >> "$file"
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
TASKNUM=$(sed -n '$ =' "$file")
|
||||
BASE=$(basename "$file")
|
||||
PREFIX=$(echo ${BASE%%.[^.]*} | tr 'a-z' 'A-Z')
|
||||
echo "$TASKNUM $input"
|
||||
echo "${PREFIX}: $TASKNUM added."
|
||||
echo "$(getPrefix "$file"): $TASKNUM added."
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -688,7 +726,7 @@ filtercommand()
|
||||
## $search_term
|
||||
#
|
||||
## Remove the first character (-) before adding to our filter command
|
||||
filter="${filter:-}${filter:+ | }grep -v -i '$(shellquote "${search_term:1}")'"
|
||||
filter="${filter:-}${filter:+ | }grep -v -i $(shellquote "${search_term:1}")"
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -774,28 +812,27 @@ _list() {
|
||||
}
|
||||
''' \
|
||||
| sed '''
|
||||
s/'${HIDE_PROJECTS_SUBSTITUTION:-^}'//g
|
||||
s/'${HIDE_CONTEXTS_SUBSTITUTION:-^}'//g
|
||||
s/'"${HIDE_PROJECTS_SUBSTITUTION:-^}"'//g
|
||||
s/'"${HIDE_CONTEXTS_SUBSTITUTION:-^}"'//g
|
||||
s/'"${HIDE_CUSTOM_SUBSTITUTION:-^}"'//g
|
||||
''' \
|
||||
| eval ${TODOTXT_FINAL_FILTER} \
|
||||
)
|
||||
[ "$filtered_items" ] && echo "$filtered_items"
|
||||
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
BASE=$(basename "$FILE")
|
||||
PREFIX=$(echo ${BASE%%.[^.]*} | tr 'a-z' 'A-Z')
|
||||
NUMTASKS=$( echo -n "$filtered_items" | sed -n '$ =' )
|
||||
TOTALTASKS=$( echo -n "$items" | sed -n '$ =' )
|
||||
|
||||
echo "--"
|
||||
echo "${PREFIX}: ${NUMTASKS:-0} of ${TOTALTASKS:-0} tasks shown"
|
||||
echo "$(getPrefix "$FILE"): ${NUMTASKS:-0} of ${TOTALTASKS:-0} tasks shown"
|
||||
fi
|
||||
if [ $TODOTXT_VERBOSE -gt 1 ]; then
|
||||
echo "TODO DEBUG: Filter Command was: ${filter_command:-cat}"
|
||||
fi
|
||||
}
|
||||
|
||||
export -f cleaninput shellquote filtercommand _list die
|
||||
export -f cleaninput getPrefix getTodo getNewtodo shellquote filtercommand _list die
|
||||
|
||||
# == HANDLE ACTION ==
|
||||
action=$( printf "%s\n" "$ACTION" | tr 'A-Z' 'a-z' )
|
||||
@@ -872,11 +909,8 @@ case $action in
|
||||
"append" | "app" )
|
||||
errmsg="usage: $TODO_SH append ITEM# \"TEXT TO APPEND\""
|
||||
shift; item=$1; shift
|
||||
getTodo "$item"
|
||||
|
||||
[ -z "$item" ] && die "$errmsg"
|
||||
[[ "$item" = +([0-9]) ]] || die "$errmsg"
|
||||
todo=$(sed "$item!d" "$TODO_FILE")
|
||||
[ -z "$todo" ] && die "TODO: No task $item."
|
||||
if [[ -z "$1" && $TODOTXT_FORCE = 0 ]]; then
|
||||
echo -n "Append: "
|
||||
read input
|
||||
@@ -891,7 +925,7 @@ case $action in
|
||||
|
||||
if sed -i.bak $item" s|^.*|&${appendspace}${input}|" "$TODO_FILE"; then
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
newtodo=$(sed "$item!d" "$TODO_FILE")
|
||||
getNewtodo "$item"
|
||||
echo "$item $newtodo"
|
||||
fi
|
||||
else
|
||||
@@ -906,14 +940,11 @@ case $action in
|
||||
# replace deleted line with a blank line when TODOTXT_PRESERVE_LINE_NUMBERS is 1
|
||||
errmsg="usage: $TODO_SH del ITEM# [TERM]"
|
||||
item=$2
|
||||
[ -z "$item" ] && die "$errmsg"
|
||||
[[ "$item" = +([0-9]) ]] || die "$errmsg"
|
||||
DELETEME=$(sed "$item!d" "$TODO_FILE")
|
||||
[ -z "$DELETEME" ] && die "TODO: No task $item."
|
||||
getTodo "$item"
|
||||
|
||||
if [ -z "$3" ]; then
|
||||
if [ $TODOTXT_FORCE = 0 ]; then
|
||||
echo "Delete '$DELETEME'? (y/n)"
|
||||
echo "Delete '$todo'? (y/n)"
|
||||
read ANSWER
|
||||
else
|
||||
ANSWER="y"
|
||||
@@ -927,7 +958,7 @@ case $action in
|
||||
sed -i.bak -e $item"s/^.*//" "$TODO_FILE"
|
||||
fi
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
echo "$item $DELETEME"
|
||||
echo "$item $todo"
|
||||
echo "TODO: $item deleted."
|
||||
fi
|
||||
else
|
||||
@@ -941,13 +972,13 @@ case $action in
|
||||
-e $item"s/ *$3 */ /g" \
|
||||
-e $item"s/$3//g" \
|
||||
"$TODO_FILE"
|
||||
newtodo=$(sed "$item!d" "$TODO_FILE")
|
||||
if [ "$DELETEME" = "$newtodo" ]; then
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item $DELETEME"
|
||||
getNewtodo "$item"
|
||||
if [ "$todo" = "$newtodo" ]; then
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "$item $todo"
|
||||
die "TODO: '$3' not found; no removal done."
|
||||
fi
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
echo "$item $DELETEME"
|
||||
echo "$item $todo"
|
||||
echo "TODO: Removed '$3' from task."
|
||||
echo "$item $newtodo"
|
||||
fi
|
||||
@@ -962,15 +993,13 @@ case $action in
|
||||
# Split multiple depri's, if comma separated change to whitespace separated
|
||||
# Loop the 'depri' function for each item
|
||||
for item in $(echo $* | tr ',' ' '); do
|
||||
[[ "$item" = +([0-9]) ]] || die "$errmsg"
|
||||
todo=$(sed "$item!d" "$TODO_FILE")
|
||||
[ -z "$todo" ] && die "TODO: No task $item."
|
||||
getTodo "$item"
|
||||
|
||||
if [[ "$todo" = \(?\)\ * ]]; then
|
||||
sed -i.bak -e $item"s/^(.) //" "$TODO_FILE"
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
NEWTODO=$(sed "$item!d" "$TODO_FILE")
|
||||
echo "$item $NEWTODO"
|
||||
getNewtodo "$item"
|
||||
echo "$item $newtodo"
|
||||
echo "TODO: $item deprioritized."
|
||||
fi
|
||||
else
|
||||
@@ -988,11 +1017,7 @@ case $action in
|
||||
# Split multiple do's, if comma separated change to whitespace separated
|
||||
# Loop the 'do' function for each item
|
||||
for item in $(echo $* | tr ',' ' '); do
|
||||
[ -z "$item" ] && die "$errmsg"
|
||||
[[ "$item" = +([0-9]) ]] || die "$errmsg"
|
||||
|
||||
todo=$(sed "$item!d" "$TODO_FILE")
|
||||
[ -z "$todo" ] && die "TODO: No task $item."
|
||||
getTodo "$item"
|
||||
|
||||
# Check if this item has already been done
|
||||
if [ "${todo:0:2}" != "x " ]; then
|
||||
@@ -1001,7 +1026,7 @@ case $action in
|
||||
sed -i.bak $item"s/^(.) //" "$TODO_FILE"
|
||||
sed -i.bak $item"s|^|x $now |" "$TODO_FILE"
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
newtodo=$(sed "$item!d" "$TODO_FILE")
|
||||
getNewtodo "$item"
|
||||
echo "$item $newtodo"
|
||||
echo "TODO: $item marked as done."
|
||||
fi
|
||||
@@ -1049,10 +1074,15 @@ case $action in
|
||||
|
||||
"listfile" | "lf" )
|
||||
shift ## Was listfile, next $1 is file name
|
||||
if [ $# -eq 0 ]; then
|
||||
[ $TODOTXT_VERBOSE -gt 0 ] && echo "Files in the todo.txt directory:"
|
||||
cd "$TODO_DIR" && ls -1 *.txt
|
||||
else
|
||||
FILE="$1"
|
||||
shift ## Was filename; next $1 is first search term
|
||||
|
||||
_list "$FILE" "$@"
|
||||
fi
|
||||
;;
|
||||
|
||||
"listcon" | "lsc" )
|
||||
@@ -1079,19 +1109,16 @@ case $action in
|
||||
dest="$TODO_DIR/$3"
|
||||
src="$TODO_DIR/$4"
|
||||
|
||||
[ -z "$item" ] && die "$errmsg"
|
||||
[ -z "$4" ] && src="$TODO_FILE"
|
||||
[ -z "$dest" ] && die "$errmsg"
|
||||
|
||||
[[ "$item" = +([0-9]) ]] || die "$errmsg"
|
||||
|
||||
[ -f "$src" ] || die "TODO: Source file $src does not exist."
|
||||
[ -f "$dest" ] || die "TODO: Destination file $dest does not exist."
|
||||
|
||||
MOVEME=$(sed "$item!d" "$src")
|
||||
[ -z "$MOVEME" ] && die "$item: No such item in $src."
|
||||
getTodo "$item" "$src"
|
||||
[ -z "$todo" ] && die "$item: No such item in $src."
|
||||
if [ $TODOTXT_FORCE = 0 ]; then
|
||||
echo "Move '$MOVEME' from $src to $dest? (y/n)"
|
||||
echo "Move '$todo' from $src to $dest? (y/n)"
|
||||
read ANSWER
|
||||
else
|
||||
ANSWER="y"
|
||||
@@ -1104,10 +1131,10 @@ case $action in
|
||||
# leave blank line behind (preserves line numbers)
|
||||
sed -i.bak -e $item"s/^.*//" "$src"
|
||||
fi
|
||||
echo "$MOVEME" >> "$dest"
|
||||
echo "$todo" >> "$dest"
|
||||
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
echo "$item $MOVEME"
|
||||
echo "$item $todo"
|
||||
echo "TODO: $item moved from '$src' to '$dest'."
|
||||
fi
|
||||
else
|
||||
@@ -1128,16 +1155,20 @@ case $action in
|
||||
note: PRIORITY must be anywhere from A to Z."
|
||||
|
||||
[ "$#" -ne 3 ] && die "$errmsg"
|
||||
[[ "$item" = +([0-9]) ]] || die "$errmsg"
|
||||
[[ "$newpri" = @([A-Z]) ]] || die "$errmsg"
|
||||
getTodo "$item"
|
||||
|
||||
oldpri=
|
||||
if [[ "$todo" = \(?\)\ * ]]; then
|
||||
oldpri=${todo:1:1}
|
||||
fi
|
||||
|
||||
oldpri=$(sed -ne $item's/^(\(.\)) .*/\1/p' "$TODO_FILE")
|
||||
if [ "$oldpri" != "$newpri" ]; then
|
||||
sed -i.bak -e $item"s/^(.) //" -e $item"s/^/($newpri) /" "$TODO_FILE"
|
||||
fi
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
NEWTODO=$(sed "$item!d" "$TODO_FILE")
|
||||
echo "$item $NEWTODO"
|
||||
getNewtodo "$item"
|
||||
echo "$item $newtodo"
|
||||
if [ "$oldpri" != "$newpri" ]; then
|
||||
if [ "$oldpri" ]; then
|
||||
echo "TODO: $item re-prioritized from ($oldpri) to ($newpri)."
|
||||
|
||||
@@ -22,10 +22,17 @@ _todo()
|
||||
local completions
|
||||
if [ $COMP_CWORD -eq 1 ]; then
|
||||
completions="$allCommands $OPTS"
|
||||
elif [[ $COMP_CWORD -gt 2 && ( \
|
||||
"${COMP_WORDS[COMP_CWORD-2]}" =~ ^(move|mv)$ || \
|
||||
"${COMP_WORDS[COMP_CWORD-3]}" =~ ^(move|mv)$ ) ]]; then
|
||||
# "move ITEM# DEST [SRC]" has file arguments on positions 2 and 3.
|
||||
completions=$(TODOTXT_VERBOSE=0 todo.sh command listfile)
|
||||
else
|
||||
case "$prev" in
|
||||
command)
|
||||
completions=$COMMANDS;;
|
||||
addto|listfile|lf)
|
||||
completions=$(TODOTXT_VERBOSE=0 todo.sh command listfile);;
|
||||
-*) completions="$allCommands $OPTS";;
|
||||
*) case "$cur" in
|
||||
+*) completions=$(TODOTXT_VERBOSE=0 todo.sh command listproj);;
|
||||
|
||||
Reference in New Issue
Block a user