Compare commits
15 Commits
archive/de
...
archive/re
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3b960a2e3c | ||
|
|
ad1ca6c2c9 | ||
|
|
36e018fd86 | ||
|
|
74858365f6 | ||
|
|
be0a0265d1 | ||
|
|
cf7f7531be | ||
|
|
28ec5a06f2 | ||
|
|
dfec12e2a4 | ||
|
|
c31716af47 | ||
|
|
ebe9fb868b | ||
|
|
189779c6de | ||
|
|
516f806d58 | ||
|
|
9e38fa11ee | ||
|
|
309b0f81b0 | ||
|
|
f3fc18af6b |
@@ -1,4 +1,57 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
[ "x$TERM" != "xdumb" ] && (
|
||||
export TERM &&
|
||||
[ -t 1 ] &&
|
||||
tput bold >/dev/null 2>&1 &&
|
||||
tput setaf 1 >/dev/null 2>&1 &&
|
||||
tput sgr0 >/dev/null 2>&1
|
||||
) &&
|
||||
color=t
|
||||
|
||||
case "$1" in
|
||||
--no-color)
|
||||
color=; shift ;;
|
||||
esac
|
||||
|
||||
if test -n "$color"; then
|
||||
say_color () {
|
||||
(
|
||||
export TERM
|
||||
case "$1" in
|
||||
error) tput bold; tput setaf 1;; # bold red
|
||||
skip) tput bold; tput setaf 2;; # bold green
|
||||
pass) tput setaf 2;; # green
|
||||
info) tput setaf 3;; # brown
|
||||
*) test -n "$quiet" && return;;
|
||||
esac
|
||||
shift
|
||||
printf "* %s" "$*"
|
||||
tput sgr0
|
||||
echo
|
||||
)
|
||||
}
|
||||
else
|
||||
say_color() {
|
||||
test -z "$1" && test -n "$quiet" && return
|
||||
shift
|
||||
echo "* $*"
|
||||
}
|
||||
fi
|
||||
|
||||
get_color()
|
||||
{
|
||||
# Only use the supplied color if there are actually instances of that
|
||||
# type, so that a clean test run does not distract the user by the
|
||||
# appearance of the error highlighting.
|
||||
if [ ${1:?} -eq 0 ]
|
||||
then
|
||||
echo 'info'
|
||||
else
|
||||
echo "${2:-info}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
fixed=0
|
||||
success=0
|
||||
@@ -27,8 +80,8 @@ do
|
||||
done <"$file"
|
||||
done
|
||||
|
||||
printf "%-8s%d\n" fixed $fixed
|
||||
printf "%-8s%d\n" success $success
|
||||
printf "%-8s%d\n" failed $failed
|
||||
printf "%-8s%d\n" broken $broken
|
||||
printf "%-8s%d\n" total $total
|
||||
say_color 'info' "$(printf "%-8s%d\n" fixed $fixed)"
|
||||
say_color "$(get_color "$success" 'pass')" "$(printf "%-8s%d\n" success $success)"
|
||||
say_color "$(get_color "$failed" 'error')" "$(printf "%-8s%d\n" failed $failed)"
|
||||
say_color "$(get_color "$broken" 'error')" "$(printf "%-8s%d\n" broken $broken)"
|
||||
say_color 'info' "$(printf "%-8s%d\n" total $total)"
|
||||
|
||||
@@ -61,6 +61,42 @@ TODO: 0 of 5 tasks shown
|
||||
TODO: 0 of 5 tasks shown
|
||||
EOF
|
||||
|
||||
cat > todo.txt <<EOF
|
||||
(B) smell the uppercase Roses +flowers @outside
|
||||
(X) clean the house from A-Z
|
||||
(C) notice the sunflowers
|
||||
(X) listen to music
|
||||
buy more records from artists A-Z
|
||||
EOF
|
||||
test_todo_session 'listpri filtering priority ranges' <<EOF
|
||||
>>> todo.sh -p listpri a-c
|
||||
1 (B) smell the uppercase Roses +flowers @outside
|
||||
3 (C) notice the sunflowers
|
||||
--
|
||||
TODO: 2 of 5 tasks shown
|
||||
|
||||
>>> todo.sh -p listpri c-Z
|
||||
3 (C) notice the sunflowers
|
||||
2 (X) clean the house from A-Z
|
||||
4 (X) listen to music
|
||||
--
|
||||
TODO: 3 of 5 tasks shown
|
||||
|
||||
>>> todo.sh -p listpri A-
|
||||
2 (X) clean the house from A-Z
|
||||
--
|
||||
TODO: 1 of 5 tasks shown
|
||||
|
||||
>>> todo.sh -p listpri A-C A-Z
|
||||
--
|
||||
TODO: 0 of 5 tasks shown
|
||||
|
||||
>>> todo.sh -p listpri X A-Z
|
||||
2 (X) clean the house from A-Z
|
||||
--
|
||||
TODO: 1 of 5 tasks shown
|
||||
EOF
|
||||
|
||||
cat > todo.txt <<EOF
|
||||
(B) ccc xxx this line should be third.
|
||||
ccc xxx this line should be third.
|
||||
|
||||
@@ -180,7 +180,7 @@ test_failure_ () {
|
||||
test_failure=$(($test_failure + 1))
|
||||
say_color error "FAIL $test_count: $1"
|
||||
shift
|
||||
echo "$@" | sed -e 's/^/ /'
|
||||
echo "$@"
|
||||
test "$immediate" = "" || { trap - EXIT; exit 1; }
|
||||
}
|
||||
|
||||
@@ -199,8 +199,9 @@ test_debug () {
|
||||
}
|
||||
|
||||
test_run_ () {
|
||||
eval >&3 2>&4 "$1"
|
||||
eval > output 2>&1 "$1"
|
||||
eval_ret="$?"
|
||||
cat >&3 output
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -260,6 +261,57 @@ test_expect_success () {
|
||||
echo >&3 ""
|
||||
}
|
||||
|
||||
test_expect_output () {
|
||||
test "$#" = 2 ||
|
||||
error "bug in the test script: not 2 parameters to test-expect-output"
|
||||
if ! test_skip "$@"
|
||||
then
|
||||
say >&3 "expecting success and output: $2"
|
||||
test_run_ "$2"
|
||||
if [ "$?" = 0 -a "$eval_ret" = 0 ]
|
||||
then
|
||||
cmp_output=$(test_cmp expect output)
|
||||
if [ "$?" = 0 ]
|
||||
then
|
||||
test_ok_ "$1"
|
||||
else
|
||||
test_failure_ "$@" "
|
||||
$cmp_output"
|
||||
fi
|
||||
else
|
||||
test_failure_ "$@"
|
||||
fi
|
||||
fi
|
||||
echo >&3 ""
|
||||
}
|
||||
|
||||
test_expect_code_and_output () {
|
||||
test "$#" = 3 ||
|
||||
error "bug in the test script: not 3 parameters to test-expect-code-and-output"
|
||||
if ! test_skip "$@"
|
||||
then
|
||||
say >&3 "expecting exit code $1 and output: $3"
|
||||
test_run_ "$3"
|
||||
if [ "$?" = 0 -a "$eval_ret" = "$1" ]
|
||||
then
|
||||
cmp_output=$(test_cmp expect output)
|
||||
if [ "$?" = 0 ]
|
||||
then
|
||||
test_ok_ "$2"
|
||||
else
|
||||
test_failure_ "$2" "$3" "
|
||||
$cmp_output"
|
||||
fi
|
||||
else
|
||||
cmp_output=$(test_cmp expect output)
|
||||
test_failure_ "$2" "$3" "
|
||||
* expected exit code $1, actual ${eval_ret}${cmp_output:+
|
||||
}${cmp_output}"
|
||||
fi
|
||||
fi
|
||||
echo >&3 ""
|
||||
}
|
||||
|
||||
test_expect_code () {
|
||||
test "$#" = 3 ||
|
||||
error "bug in the test script: not 3 parameters to test-expect-code"
|
||||
@@ -271,7 +323,8 @@ test_expect_code () {
|
||||
then
|
||||
test_ok_ "$2"
|
||||
else
|
||||
test_failure_ "$@"
|
||||
test_failure_ "$2" "$3" "
|
||||
* expected exit code $1, actual ${eval_ret}"
|
||||
fi
|
||||
fi
|
||||
echo >&3 ""
|
||||
@@ -542,9 +595,9 @@ test_todo_session () {
|
||||
"")
|
||||
if [ ! -z "$cmd" ]; then
|
||||
if [ $status = 0 ]; then
|
||||
test_expect_success "$1 $subnum" "$cmd > output && test_cmp expect output"
|
||||
test_expect_output "$1 $subnum" "$cmd"
|
||||
else
|
||||
test_expect_success "$1 $subnum" "$cmd > output ; test \$? = $status && test_cmp expect output"
|
||||
test_expect_code_and_output "$status" "$1 $subnum" "$cmd"
|
||||
fi
|
||||
|
||||
subnum=$(($subnum + 1))
|
||||
@@ -560,9 +613,9 @@ test_todo_session () {
|
||||
done
|
||||
if [ ! -z "$cmd" ]; then
|
||||
if [ $status = 0 ]; then
|
||||
test_expect_success "$1 $subnum" "$cmd > output && test_cmp expect output"
|
||||
test_expect_output "$1 $subnum" "$cmd"
|
||||
else
|
||||
test_expect_success "$1 $subnum" "$cmd > output ; test \$? = $status && test_cmp expect output"
|
||||
test_expect_code_and_output "$status" "$1 $subnum" "$cmd"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
1
todo.cfg
1
todo.cfg
@@ -8,7 +8,6 @@ export TODO_DIR=`dirname "$0"`
|
||||
export TODO_FILE="$TODO_DIR/todo.txt"
|
||||
export DONE_FILE="$TODO_DIR/done.txt"
|
||||
export REPORT_FILE="$TODO_DIR/report.txt"
|
||||
export TMP_FILE="$TODO_DIR/todo.tmp"
|
||||
|
||||
# You can customize your actions directory location
|
||||
#export TODO_ACTIONS_DIR="$HOME/.todo.actions.d"
|
||||
|
||||
91
todo.sh
91
todo.sh
@@ -59,7 +59,7 @@ shorthelp()
|
||||
listall|lsa [TERM...]
|
||||
listcon|lsc
|
||||
listfile|lf [SRC [TERM...]]
|
||||
listpri|lsp [PRIORITY] [TERM...]
|
||||
listpri|lsp [PRIORITIES] [TERM...]
|
||||
listproj|lsprj [TERM...]
|
||||
move|mv ITEM# DEST [SRC]
|
||||
prepend|prep ITEM# "TEXT TO PREPEND"
|
||||
@@ -231,10 +231,11 @@ help()
|
||||
Without any arguments, the names of all text files in the todo.txt
|
||||
directory are listed.
|
||||
|
||||
listpri [PRIORITY] [TERM...]
|
||||
lsp [PRIORITY] [TERM...]
|
||||
Displays all tasks prioritized PRIORITY.
|
||||
If no PRIORITY specified, lists all prioritized tasks.
|
||||
listpri [PRIORITIES] [TERM...]
|
||||
lsp [PRIORITIES] [TERM...]
|
||||
Displays all tasks prioritized PRIORITIES.
|
||||
PRIORITIES can be a single one (A) or a range (A-C).
|
||||
If no PRIORITIES specified, lists all prioritized tasks.
|
||||
If TERM specified, lists only prioritized tasks that contain TERM(s).
|
||||
Hides all tasks that contain TERM(s) preceded by a minus sign
|
||||
(i.e. -TERM).
|
||||
@@ -302,12 +303,6 @@ die()
|
||||
exit 1
|
||||
}
|
||||
|
||||
cleanup()
|
||||
{
|
||||
[ -f "$TMP_FILE" ] && rm "$TMP_FILE"
|
||||
return 0
|
||||
}
|
||||
|
||||
cleaninput()
|
||||
{
|
||||
# Parameters: When $1 = "for sed", performs additional escaping for use
|
||||
@@ -670,7 +665,6 @@ ACTION=${1:-$TODOTXT_DEFAULT_ACTION}
|
||||
[ -d "$TODO_DIR" ] || die "Fatal Error: $TODO_DIR is not a directory"
|
||||
( cd "$TODO_DIR" ) || die "Fatal Error: Unable to cd to $TODO_DIR"
|
||||
|
||||
[ -w "$TMP_FILE" ] || echo -n > "$TMP_FILE" || die "Fatal Error: Unable to write to $TMP_FILE"
|
||||
[ -f "$TODO_FILE" ] || cp /dev/null "$TODO_FILE"
|
||||
[ -f "$DONE_FILE" ] || cp /dev/null "$DONE_FILE"
|
||||
[ -f "$REPORT_FILE" ] || cp /dev/null "$REPORT_FILE"
|
||||
@@ -760,13 +754,32 @@ _list() {
|
||||
## Get our search arguments, if any
|
||||
shift ## was file name, new $1 is first search term
|
||||
|
||||
## Build the filter.
|
||||
filter_command=$(filtercommand "${pre_filter_command:-}" "${post_filter_command:-}" "$@")
|
||||
_format "$src" '' "$@"
|
||||
|
||||
## Figure out how much padding we need to use
|
||||
## We need one level of padding for each power of 10 $LINES uses
|
||||
LINES=$( sed -n '$ =' "$src" )
|
||||
PADDING=${#LINES}
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
echo "--"
|
||||
echo "$(getPrefix "$src"): ${NUMTASKS:-0} of ${TOTALTASKS:-0} tasks shown"
|
||||
fi
|
||||
}
|
||||
getPadding()
|
||||
{
|
||||
## We need one level of padding for each power of 10 $LINES uses.
|
||||
LINES=$(sed -n '$ =' "${1:-$TODO_FILE}")
|
||||
printf %s ${#LINES}
|
||||
}
|
||||
_format()
|
||||
{
|
||||
# Parameters: $1: todo input file; when empty formats stdin
|
||||
# $2: ITEM# number width; if empty auto-detects from $1 / $TODO_FILE.
|
||||
# Precondition: None
|
||||
# Postcondition: $NUMTASKS and $TOTALTASKS contain statistics (unless $TODOTXT_VERBOSE=0).
|
||||
|
||||
FILE=$1
|
||||
shift
|
||||
|
||||
## Figure out how much padding we need to use, unless this was passed to us.
|
||||
PADDING=${1:-$(getPadding "$FILE")}
|
||||
shift
|
||||
|
||||
## Number the file, then run the filter command,
|
||||
## then sort and mangle output some more
|
||||
@@ -774,14 +787,21 @@ _list() {
|
||||
TODOTXT_FINAL_FILTER="cat"
|
||||
fi
|
||||
items=$(
|
||||
sed = "$src" \
|
||||
| sed '''
|
||||
if [ "$FILE" ]; then
|
||||
sed = "$FILE"
|
||||
else
|
||||
sed =
|
||||
fi \
|
||||
| sed -e '''
|
||||
N
|
||||
s/^/ /
|
||||
s/ *\([ 0-9]\{'"$PADDING"',\}\)\n/\1 /
|
||||
''' \
|
||||
| grep -v "^[ 0-9]\+ *$"
|
||||
/^[ 0-9]\{1,\} *$/d
|
||||
'''
|
||||
)
|
||||
|
||||
## Build and apply the filter.
|
||||
filter_command=$(filtercommand "${pre_filter_command:-}" "${post_filter_command:-}" "$@")
|
||||
if [ "${filter_command}" ]; then
|
||||
filtered_items=$(echo -n "$items" | eval "${filter_command}")
|
||||
else
|
||||
@@ -806,7 +826,7 @@ _list() {
|
||||
{
|
||||
if (match($0, /^[0-9]+ x /)) {
|
||||
print highlight("COLOR_DONE") $0 highlight("DEFAULT")
|
||||
} else if (match($0, /^[0-9]+ \([A-Z]\)[[:space:]]/)) {
|
||||
} else if (match($0, /^[0-9]+ \([A-Z]\) /)) {
|
||||
clr = highlight("PRI_" substr($0, RSTART + RLENGTH - 3, 1))
|
||||
print \
|
||||
(clr ? clr : highlight("PRI_X")) \
|
||||
@@ -827,16 +847,13 @@ _list() {
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
NUMTASKS=$( echo -n "$filtered_items" | sed -n '$ =' )
|
||||
TOTALTASKS=$( echo -n "$items" | sed -n '$ =' )
|
||||
|
||||
echo "--"
|
||||
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 getPrefix getTodo getNewtodo shellquote filtercommand _list die
|
||||
export -f cleaninput getPrefix getTodo getNewtodo shellquote filtercommand _list getPadding _format die
|
||||
|
||||
# == HANDLE ACTION ==
|
||||
action=$( printf "%s\n" "$ACTION" | tr 'A-Z' 'a-z' )
|
||||
@@ -854,9 +871,7 @@ then
|
||||
elif [ -d "$TODO_ACTIONS_DIR" -a -x "$TODO_ACTIONS_DIR/$action" ]
|
||||
then
|
||||
"$TODO_ACTIONS_DIR/$action" "$@"
|
||||
status=$?
|
||||
cleanup
|
||||
exit $status
|
||||
exit $?
|
||||
fi
|
||||
|
||||
## Only run if $action isn't found in .todo.actions.d
|
||||
@@ -1082,16 +1097,16 @@ case $action in
|
||||
"listall" | "lsa" )
|
||||
shift ## Was lsa; new $1 is first search term
|
||||
|
||||
cat "$TODO_FILE" "$DONE_FILE" > "$TMP_FILE"
|
||||
TOTAL=$( sed -n '$ =' "$TODO_FILE" )
|
||||
PADDING=${#TOTAL}
|
||||
|
||||
post_filter_command="awk -v TOTAL=$TOTAL -v PADDING=${#TOTAL} '{ \$1 = sprintf(\"%\" PADDING \"d\", (\$1 > TOTAL ? 0 : \$1)); print }' "
|
||||
TODOTXT_VERBOSE=0 _list "$TMP_FILE" "$@"
|
||||
post_filter_command="awk -v TOTAL=$TOTAL -v PADDING=$PADDING '{ \$1 = sprintf(\"%\" PADDING \"d\", (\$1 > TOTAL ? 0 : \$1)); print }' "
|
||||
cat "$TODO_FILE" "$DONE_FILE" | TODOTXT_VERBOSE=0 _format '' "$PADDING" "$@"
|
||||
|
||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||
TDONE=$( sed -n '$ =' "$DONE_FILE" )
|
||||
TASKNUM=$(TODOTXT_PLAIN=1 TODOTXT_VERBOSE=0 _list "$TODO_FILE" "$@" | sed -n '$ =')
|
||||
DONENUM=$(TODOTXT_PLAIN=1 TODOTXT_VERBOSE=0 _list "$DONE_FILE" "$@" | sed -n '$ =')
|
||||
TASKNUM=$(TODOTXT_PLAIN=1 TODOTXT_VERBOSE=0 _format "$TODO_FILE" 1 "$@" | sed -n '$ =')
|
||||
DONENUM=$(TODOTXT_PLAIN=1 TODOTXT_VERBOSE=0 _format "$DONE_FILE" 1 "$@" | sed -n '$ =')
|
||||
echo "--"
|
||||
echo "$(getPrefix "$TODO_FILE"): ${TASKNUM:-0} of ${TOTAL:-0} tasks shown"
|
||||
echo "$(getPrefix "$DONE_FILE"): ${DONENUM:-0} of ${TDONE:-0} tasks shown"
|
||||
@@ -1124,8 +1139,8 @@ case $action in
|
||||
"listpri" | "lsp" )
|
||||
shift ## was "listpri", new $1 is priority to list or first TERM
|
||||
|
||||
pri=$(printf "%s\n" "$1" | tr 'a-z' 'A-Z' | grep '^[A-Z]$') && shift || pri="[A-Z]"
|
||||
post_filter_command="grep '^ *[0-9]\+ (${pri}) '"
|
||||
pri=$(printf "%s\n" "$1" | tr 'a-z' 'A-Z' | grep -e '^[A-Z]$' -e '^[A-Z]-[A-Z]$') && shift || pri="A-Z"
|
||||
post_filter_command="grep '^ *[0-9]\+ ([${pri}]) '"
|
||||
_list "$TODO_FILE" "$@"
|
||||
;;
|
||||
|
||||
@@ -1283,5 +1298,3 @@ note: PRIORITY must be anywhere from A to Z."
|
||||
* )
|
||||
usage;;
|
||||
esac
|
||||
|
||||
cleanup
|
||||
|
||||
Reference in New Issue
Block a user