Compare commits
5 Commits
archive/no
...
archive/ls
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a0f39480bf | ||
|
|
d804a78fa1 | ||
|
|
84880ba525 | ||
|
|
72fe73f3d8 | ||
|
|
8f6070e702 |
@@ -10,8 +10,7 @@ On failure, it will print each offending line number and line.
|
||||
. ./test-lib.sh
|
||||
|
||||
test_todo_session 'no old-style backtick command substitution' <<EOF
|
||||
>>> sed -n -e 's/\(^\|[ \t]\)#.*//' -e '/\d96/{=;p}' "$(which todo.sh)"
|
||||
>>> sed -n -e 's/\(^\|[ \t]\)#.*//' -e '/\`/{' -e '=;p' -e '}' "$(which todo.sh)"
|
||||
EOF
|
||||
# Note: Must encode backtick as \d96 to avoid error in the test framework.
|
||||
|
||||
test_done
|
||||
|
||||
@@ -53,6 +53,25 @@ TODO: 2 prioritized (C).
|
||||
--
|
||||
TODO: 3 of 3 tasks shown
|
||||
|
||||
>>> todo.sh add "smell the coffee +wakeup"
|
||||
4 smell the coffee +wakeup
|
||||
TODO: 4 added.
|
||||
|
||||
>>> todo.sh -p list
|
||||
1 (B) smell the uppercase Roses +flowers @outside
|
||||
2 (C) notice the sunflowers
|
||||
4 smell the coffee +wakeup
|
||||
3 stop
|
||||
--
|
||||
TODO: 4 of 4 tasks shown
|
||||
EOF
|
||||
|
||||
cat > todo.txt <<EOF
|
||||
(B) smell the uppercase Roses +flowers @outside
|
||||
(C) notice the sunflowers
|
||||
stop
|
||||
EOF
|
||||
test_todo_session 'reprioritize' <<EOF
|
||||
>>> todo.sh pri 2 A
|
||||
2 (A) notice the sunflowers
|
||||
TODO: 2 re-prioritized from (C) to (A).
|
||||
@@ -68,23 +87,11 @@ TODO: 3 of 3 tasks shown
|
||||
2 (A) notice the sunflowers
|
||||
TODO: 2 already prioritized (A).
|
||||
|
||||
>>> todo.sh -p listpri
|
||||
2 (A) notice the sunflowers
|
||||
1 (B) smell the uppercase Roses +flowers @outside
|
||||
--
|
||||
TODO: 2 of 3 tasks shown
|
||||
|
||||
>>> todo.sh add "smell the coffee +wakeup"
|
||||
4 smell the coffee +wakeup
|
||||
TODO: 4 added.
|
||||
|
||||
>>> todo.sh -p list
|
||||
2 (A) notice the sunflowers
|
||||
1 (B) smell the uppercase Roses +flowers @outside
|
||||
4 smell the coffee +wakeup
|
||||
3 stop
|
||||
--
|
||||
TODO: 4 of 4 tasks shown
|
||||
TODO: 3 of 3 tasks shown
|
||||
EOF
|
||||
|
||||
test_done
|
||||
|
||||
@@ -4,13 +4,6 @@ test_description='list priority functionality
|
||||
'
|
||||
. ./test-lib.sh
|
||||
|
||||
test_todo_session 'listpri usage' <<EOF
|
||||
>>> todo.sh listpri ?
|
||||
usage: todo.sh listpri PRIORITY
|
||||
note: PRIORITY must a single letter from A to Z.
|
||||
=== 1
|
||||
EOF
|
||||
|
||||
cat > todo.txt <<EOF
|
||||
(B) smell the uppercase Roses +flowers @outside
|
||||
(C) notice the sunflowers
|
||||
@@ -42,7 +35,7 @@ cat > todo.txt <<EOF
|
||||
(n) not a prioritized task
|
||||
notice the (C)opyright
|
||||
EOF
|
||||
test_todo_session 'listpri filtering' <<EOF
|
||||
test_todo_session 'listpri filtering priorities' <<EOF
|
||||
>>> todo.sh -p listpri
|
||||
1 (B) smell the uppercase Roses +flowers @outside
|
||||
2 (C) notice the sunflowers
|
||||
@@ -68,4 +61,35 @@ TODO: 0 of 5 tasks shown
|
||||
TODO: 0 of 5 tasks shown
|
||||
EOF
|
||||
|
||||
cat > todo.txt <<EOF
|
||||
(B) ccc xxx this line should be third.
|
||||
ccc xxx this line should be third.
|
||||
(A) aaa zzz this line should be first.
|
||||
aaa zzz this line should be first.
|
||||
(B) bbb yyy this line should be second.
|
||||
bbb yyy this line should be second.
|
||||
EOF
|
||||
test_todo_session 'listpri filtering of TERM' <<EOF
|
||||
>>> todo.sh -p listpri "should be"
|
||||
3 (A) aaa zzz this line should be first.
|
||||
5 (B) bbb yyy this line should be second.
|
||||
1 (B) ccc xxx this line should be third.
|
||||
--
|
||||
TODO: 3 of 6 tasks shown
|
||||
|
||||
>>> todo.sh -p listpri a "should be"
|
||||
3 (A) aaa zzz this line should be first.
|
||||
--
|
||||
TODO: 1 of 6 tasks shown
|
||||
|
||||
>>> todo.sh -p listpri b second
|
||||
5 (B) bbb yyy this line should be second.
|
||||
--
|
||||
TODO: 1 of 6 tasks shown
|
||||
|
||||
>>> todo.sh -p listpri x "should be"
|
||||
--
|
||||
TODO: 0 of 6 tasks shown
|
||||
EOF
|
||||
|
||||
test_done
|
||||
|
||||
42
tests/t1260-listprj.sh
Executable file
42
tests/t1260-listprj.sh
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/bin/sh
|
||||
|
||||
test_description='list project functionality
|
||||
'
|
||||
. ./test-lib.sh
|
||||
|
||||
cat > todo.txt <<EOF
|
||||
(B) smell the uppercase Roses +roses @outside +shared
|
||||
(C) notice the sunflowers +sunflowers @garden +shared +landscape
|
||||
stop
|
||||
EOF
|
||||
test_todo_session 'basic listproj' <<EOF
|
||||
>>> todo.sh listproj
|
||||
+landscape
|
||||
+roses
|
||||
+shared
|
||||
+sunflowers
|
||||
EOF
|
||||
|
||||
test_todo_session 'listproj with context' <<EOF
|
||||
>>> todo.sh listproj @garden
|
||||
+landscape
|
||||
+shared
|
||||
+sunflowers
|
||||
EOF
|
||||
|
||||
TEST_TODO_CUSTOM=todo-custom.cfg
|
||||
cat todo.cfg > "$TEST_TODO_CUSTOM"
|
||||
cat >> "$TEST_TODO_CUSTOM" <<'EOF'
|
||||
export DEFAULT='</color>'
|
||||
export PRI_B='<color type=green>'
|
||||
export PRI_C='<color type=blue>'
|
||||
export TODOTXT_FINAL_FILTER='grep -i roses'
|
||||
EOF
|
||||
test_todo_session 'listproj with context special cases' <<EOF
|
||||
>>> todo.sh -+ -d "$TEST_TODO_CUSTOM" listproj @garden
|
||||
+landscape
|
||||
+shared
|
||||
+sunflowers
|
||||
EOF
|
||||
|
||||
test_done
|
||||
@@ -94,6 +94,40 @@ TODO: 1 of 3 tasks shown
|
||||
TODO: 1 of 3 tasks shown
|
||||
EOF
|
||||
|
||||
#
|
||||
# check the filtering of TERM containing characters that are special to the
|
||||
# shell, like variables, quotes, and multiple subsequent spaces.
|
||||
#
|
||||
cat > todo.txt <<'EOF'
|
||||
earn some pennies
|
||||
earn some $$
|
||||
earn some "money"
|
||||
get money from O'Brian
|
||||
just get money!
|
||||
EOF
|
||||
test_todo_session 'checking filtering of special characters' <<'EOF'
|
||||
>>> todo.sh ls '$$'
|
||||
2 earn some $$
|
||||
--
|
||||
TODO: 1 of 5 tasks shown
|
||||
|
||||
>>> todo.sh ls '"money"'
|
||||
3 earn some "money"
|
||||
--
|
||||
TODO: 1 of 5 tasks shown
|
||||
|
||||
>>> todo.sh ls "O'Brian"
|
||||
4 get money from O'Brian
|
||||
--
|
||||
TODO: 1 of 5 tasks shown
|
||||
|
||||
>>> todo.sh ls "get money"
|
||||
5 just get money!
|
||||
--
|
||||
TODO: 1 of 5 tasks shown
|
||||
EOF
|
||||
|
||||
|
||||
#
|
||||
# check the x command line option
|
||||
#
|
||||
|
||||
90
todo.sh
90
todo.sh
@@ -59,7 +59,7 @@ shorthelp()
|
||||
listcon|lsc
|
||||
listfile|lf SRC [TERM...]
|
||||
listpri|lsp [PRIORITY] [TERM...]
|
||||
listproj|lsprj
|
||||
listproj|lsprj [TERM...]
|
||||
move|mv ITEM# DEST [SRC]
|
||||
prepend|prep ITEM# "TEXT TO PREPEND"
|
||||
pri|p ITEM# PRIORITY
|
||||
@@ -633,6 +633,42 @@ _addto() {
|
||||
fi
|
||||
}
|
||||
|
||||
shellquote()
|
||||
{
|
||||
typeset -r qq=\'; printf %s\\n "'${1//\'/${qq}\\${qq}${qq}}'";
|
||||
}
|
||||
|
||||
filtercommand()
|
||||
{
|
||||
filter=${1:-}
|
||||
shift
|
||||
post_filter=${1:-}
|
||||
shift
|
||||
|
||||
for search_term
|
||||
do
|
||||
## See if the first character of $search_term is a dash
|
||||
if [ "${search_term:0:1}" != '-' ]
|
||||
then
|
||||
## First character isn't a dash: hide lines that don't match
|
||||
## this $search_term
|
||||
filter="${filter:-}${filter:+ | }grep -i $(shellquote "$search_term")"
|
||||
else
|
||||
## First character is a dash: hide lines that match this
|
||||
## $search_term
|
||||
#
|
||||
## Remove the first character (-) before adding to our filter command
|
||||
filter="${filter:-}${filter:+ | }grep -v -i '$(shellquote "${search_term:1}")'"
|
||||
fi
|
||||
done
|
||||
|
||||
[ -n "$post_filter" ] && {
|
||||
filter="${filter:-}${filter:+ | }${post_filter:-}"
|
||||
}
|
||||
|
||||
printf %s "$filter"
|
||||
}
|
||||
|
||||
_list() {
|
||||
local FILE="$1"
|
||||
## If the file starts with a "/" use absolute path. Otherwise,
|
||||
@@ -656,32 +692,8 @@ _list() {
|
||||
## Get our search arguments, if any
|
||||
shift ## was file name, new $1 is first search term
|
||||
|
||||
## Prefix the filter_command with the pre_filter_command
|
||||
filter_command="${pre_filter_command:-}"
|
||||
|
||||
for search_term
|
||||
do
|
||||
## See if the first character of $search_term is a dash
|
||||
if [ "${search_term:0:1}" != '-' ]
|
||||
then
|
||||
## First character isn't a dash: hide lines that don't match
|
||||
## this $search_term
|
||||
filter_command="${filter_command:-} ${filter_command:+|} \
|
||||
grep -i \"$search_term\" "
|
||||
else
|
||||
## First character is a dash: hide lines that match this
|
||||
## $search_term
|
||||
#
|
||||
## Remove the first character (-) before adding to our filter command
|
||||
filter_command="${filter_command:-} ${filter_command:+|} \
|
||||
grep -v -i \"${search_term:1}\" "
|
||||
fi
|
||||
done
|
||||
|
||||
## If post_filter_command is set, append it to the filter_command
|
||||
[ -n "$post_filter_command" ] && {
|
||||
filter_command="${filter_command:-}${filter_command:+ | }${post_filter_command:-}"
|
||||
}
|
||||
## Build the filter.
|
||||
filter_command=$(filtercommand "${pre_filter_command:-}" "${post_filter_command:-}" "$@")
|
||||
|
||||
## Figure out how much padding we need to use
|
||||
## We need one level of padding for each power of 10 $LINES uses
|
||||
@@ -699,7 +711,7 @@ _list() {
|
||||
| grep -v "^[ 0-9]\+ *$"
|
||||
)
|
||||
if [ "${filter_command}" ]; then
|
||||
filtered_items=$(echo -n "$items" | eval ${filter_command})
|
||||
filtered_items=$(echo -n "$items" | eval "${filter_command}")
|
||||
else
|
||||
filtered_items=$items
|
||||
fi
|
||||
@@ -752,7 +764,7 @@ _list() {
|
||||
fi
|
||||
}
|
||||
|
||||
export -f cleaninput _list die
|
||||
export -f cleaninput shellquote filtercommand _list die
|
||||
|
||||
# == HANDLE ACTION ==
|
||||
action=$( printf "%s\n" "$ACTION" | tr 'A-Z' 'a-z' )
|
||||
@@ -923,7 +935,7 @@ case $action in
|
||||
todo=$(sed "$item!d" "$TODO_FILE")
|
||||
[ -z "$todo" ] && die "TODO: No task $item."
|
||||
|
||||
if sed "$item!d" "$TODO_FILE" | grep "^(.) " > /dev/null; then
|
||||
if [[ "$todo" = \(?\)\ * ]]; then
|
||||
sed -i.bak -e $item"s/^(.) //" "$TODO_FILE"
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
NEWTODO=$(sed "$item!d" "$TODO_FILE")
|
||||
@@ -944,7 +956,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
|
||||
for item in $(echo $* | tr ',' ' '); do
|
||||
[ -z "$item" ] && die "$errmsg"
|
||||
[[ "$item" = +([0-9]) ]] || die "$errmsg"
|
||||
|
||||
@@ -1007,24 +1019,14 @@ case $action in
|
||||
;;
|
||||
|
||||
"listproj" | "lsprj" )
|
||||
grep -o '[^ ]*+[^ ]\+' "$TODO_FILE" | grep '^+' | sort -u
|
||||
shift
|
||||
eval "$(filtercommand 'cat "$TODO_FILE"' '' "$@")" | grep -o '[^ ]*+[^ ]\+' | grep '^+' | sort -u
|
||||
;;
|
||||
|
||||
"listpri" | "lsp" )
|
||||
shift ## was "listpri", new $1 is priority to list or first TERM
|
||||
|
||||
if [ "${1:-}" ]
|
||||
then
|
||||
## A priority was specified
|
||||
pri=$( printf "%s\n" "$1" | tr 'a-z' 'A-Z' | grep '^[A-Z]$' ) || {
|
||||
die "usage: $TODO_SH listpri PRIORITY
|
||||
note: PRIORITY must a single letter from A to Z."
|
||||
}
|
||||
else
|
||||
## No priority specified; show all priority tasks
|
||||
pri="[A-Z]"
|
||||
fi
|
||||
|
||||
pri=$(printf "%s\n" "$1" | tr 'a-z' 'A-Z' | grep '^[A-Z]$') && shift || pri="[A-Z]"
|
||||
post_filter_command="grep '^ *[0-9]\+ (${pri}) '"
|
||||
_list "$TODO_FILE" "$@"
|
||||
;;
|
||||
|
||||
Reference in New Issue
Block a user