Compare commits
8 Commits
archive/re
...
archive/co
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f4145348d0 | ||
|
|
c9a158338b | ||
|
|
6132bdeb47 | ||
|
|
213f6afa38 | ||
|
|
7db3a2de13 | ||
|
|
4f504b26c9 | ||
|
|
6c950429f6 | ||
|
|
9fb52d04e6 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,6 +1,3 @@
|
|||||||
VERSION-FILE
|
VERSION-FILE
|
||||||
tests/test-results
|
tests/test-results
|
||||||
tests/trash\ directory.*
|
tests/trash\ directory.*
|
||||||
done.txt
|
|
||||||
report.txt
|
|
||||||
todo.txt
|
|
||||||
|
|||||||
@@ -164,12 +164,4 @@ TODO: Replaced task with:
|
|||||||
1 (A) 2010-07-04 this also has a new date
|
1 (A) 2010-07-04 this also has a new date
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
echo '2009-02-13 this is just a new one' > todo.txt
|
|
||||||
test_todo_session 'replace with prepended priority and date replaces existing date' <<EOF
|
|
||||||
>>> todo.sh replace 1 '(B) 2010-07-04 this also has a new date'
|
|
||||||
1 2009-02-13 this is just a new one
|
|
||||||
TODO: Replaced task with:
|
|
||||||
1 (B) 2010-07-04 this also has a new date
|
|
||||||
EOF
|
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ This test checks basic todo_completion of actions and options
|
|||||||
'
|
'
|
||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
|
|
||||||
readonly ACTIONS='add a addto addm append app archive command del rm depri dp do help list ls listaddons listall lsa listcon lsc listfile lf listpri lsp listproj lsprj move mv prepend prep pri p replace report shorthelp'
|
readonly ACTIONS='add a addto addm append app archive command del rm depri dp do help list ls listall lsa listcon lsc listfile lf listpri lsp listproj lsprj move mv prepend prep pri p replace report shorthelp'
|
||||||
readonly OPTIONS='-@ -@@ -+ -++ -d -f -h -p -P -PP -a -n -t -v -vv -V -x'
|
readonly OPTIONS='-@ -@@ -+ -++ -d -f -h -p -P -PP -a -n -t -v -vv -V -x'
|
||||||
|
|
||||||
test_todo_completion 'all arguments' 'todo.sh ' "$ACTIONS $OPTIONS"
|
test_todo_completion 'all arguments' 'todo.sh ' "$ACTIONS $OPTIONS"
|
||||||
|
|||||||
@@ -7,68 +7,20 @@ This test checks todo_completion of custom actions in .todo.actions.d
|
|||||||
'
|
'
|
||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
|
|
||||||
readonly ACTIONS='add a addto addm append app archive command del rm depri dp do help list ls listaddons listall lsa listcon lsc listfile lf listpri lsp listproj lsprj move mv prepend prep pri p replace report shorthelp'
|
readonly ACTIONS='add a addto addm append app archive command del rm depri dp do help list ls listall lsa listcon lsc listfile lf listpri lsp listproj lsprj move mv prepend prep pri p replace report shorthelp'
|
||||||
readonly OPTIONS='-@ -@@ -+ -++ -d -f -h -p -P -PP -a -n -t -v -vv -V -x'
|
readonly OPTIONS='-@ -@@ -+ -++ -d -f -h -p -P -PP -a -n -t -v -vv -V -x'
|
||||||
|
|
||||||
readonly ADDONS='bar baz foobar'
|
readonly ADDONS='bar baz foobar'
|
||||||
makeCustomActions()
|
mkdir "$HOME/.todo.actions.d"
|
||||||
{
|
|
||||||
set -e
|
|
||||||
mkdir "${1:?}"
|
|
||||||
for addon in $ADDONS
|
for addon in $ADDONS
|
||||||
do
|
do
|
||||||
addonFile="${1}/$addon"
|
> "$HOME/.todo.actions.d/$addon"
|
||||||
> "$addonFile"
|
chmod +x "$HOME/.todo.actions.d/$addon"
|
||||||
chmod +x "$addonFile"
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# Also create a subdirectory, to test that it is skipped.
|
|
||||||
mkdir "${1}/subdir"
|
|
||||||
|
|
||||||
# Also create a non-executable file, to test that it is skipped.
|
|
||||||
datafile="${1:?}/datafile"
|
|
||||||
> "$datafile"
|
|
||||||
chmod -x "$datafile"
|
|
||||||
[ -x "$datafile" ] && rm "$datafile" # Some file systems may always make files executable; then, skip this check.
|
|
||||||
|
|
||||||
set +e
|
|
||||||
}
|
|
||||||
removeCustomActions()
|
|
||||||
{
|
|
||||||
set -e
|
|
||||||
rmdir "${1}/subdir"
|
|
||||||
rm "${1:?}/"*
|
|
||||||
rmdir "$1"
|
|
||||||
set +e
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Test resolution of the default TODO_ACTIONS_DIR.
|
|
||||||
#
|
|
||||||
makeCustomActions "$HOME/.todo.actions.d"
|
|
||||||
test_todo_completion 'all arguments' 'todo.sh ' "$ACTIONS $ADDONS $OPTIONS"
|
test_todo_completion 'all arguments' 'todo.sh ' "$ACTIONS $ADDONS $OPTIONS"
|
||||||
test_todo_completion 'all arguments after option' 'todo.sh -a ' "$ACTIONS $ADDONS $OPTIONS"
|
test_todo_completion 'all arguments after option' 'todo.sh -a ' "$ACTIONS $ADDONS $OPTIONS"
|
||||||
test_todo_completion 'all arguments beginning with b' 'todo.sh b' 'bar baz'
|
test_todo_completion 'all arguments beginning with b' 'todo.sh b' 'bar baz'
|
||||||
test_todo_completion 'all arguments beginning with f after options' 'todo.sh -a -v f' 'foobar'
|
test_todo_completion 'all arguments beginning with f after options' 'todo.sh -a -v f' 'foobar'
|
||||||
test_todo_completion 'nothing after addon action' 'todo.sh foobar ' ''
|
test_todo_completion 'nothing after addon action' 'todo.sh foobar ' ''
|
||||||
removeCustomActions "$HOME/.todo.actions.d"
|
|
||||||
|
|
||||||
#
|
|
||||||
# Test resolution of an alternative TODO_ACTIONS_DIR.
|
|
||||||
#
|
|
||||||
mkdir "$HOME/.todo"
|
|
||||||
makeCustomActions "$HOME/.todo/actions"
|
|
||||||
test_todo_completion 'all arguments with actions from .todo/actions/' 'todo.sh ' "$ACTIONS $ADDONS $OPTIONS"
|
|
||||||
removeCustomActions "$HOME/.todo/actions"
|
|
||||||
|
|
||||||
#
|
|
||||||
# Test resolution of a configured TODO_ACTIONS_DIR.
|
|
||||||
#
|
|
||||||
makeCustomActions "$HOME/addons"
|
|
||||||
cat >> todo.cfg <<'EOF'
|
|
||||||
export TODO_ACTIONS_DIR="$HOME/addons"
|
|
||||||
EOF
|
|
||||||
test_todo_completion 'all arguments with actions from addons/' 'todo.sh ' "$ACTIONS $ADDONS $OPTIONS"
|
|
||||||
removeCustomActions "$HOME/addons"
|
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|||||||
29
todo.sh
29
todo.sh
@@ -57,7 +57,6 @@ shorthelp()
|
|||||||
help
|
help
|
||||||
list|ls [TERM...]
|
list|ls [TERM...]
|
||||||
listall|lsa [TERM...]
|
listall|lsa [TERM...]
|
||||||
listaddons
|
|
||||||
listcon|lsc
|
listcon|lsc
|
||||||
listfile|lf [SRC [TERM...]]
|
listfile|lf [SRC [TERM...]]
|
||||||
listpri|lsp [PRIORITIES] [TERM...]
|
listpri|lsp [PRIORITIES] [TERM...]
|
||||||
@@ -220,9 +219,6 @@ help()
|
|||||||
TERM specified, lists entire todo.txt AND done.txt
|
TERM specified, lists entire todo.txt AND done.txt
|
||||||
concatenated and sorted.
|
concatenated and sorted.
|
||||||
|
|
||||||
listaddons
|
|
||||||
Lists all added and overridden actions in the actions directory.
|
|
||||||
|
|
||||||
listcon
|
listcon
|
||||||
lsc
|
lsc
|
||||||
Lists all the task contexts that start with the @ sign in todo.txt.
|
Lists all the task contexts that start with the @ sign in todo.txt.
|
||||||
@@ -389,22 +385,21 @@ replaceOrPrepend()
|
|||||||
else
|
else
|
||||||
input=$*
|
input=$*
|
||||||
fi
|
fi
|
||||||
|
cleaninput "for sed"
|
||||||
|
|
||||||
# Retrieve existing priority and prepended date
|
# Retrieve existing priority and prepended date
|
||||||
local -r priAndDateExpr='^\((.) \)\{0,1\}\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} \)\{0,1\}'
|
priority=$(sed -e "$item!d" -e $item's/^\((.) \)\{0,1\}\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} \)\{0,1\}.*/\1/' "$TODO_FILE")
|
||||||
priority=$(sed -e "$item!d" -e "${item}s/${priAndDateExpr}.*/\\1/" "$TODO_FILE")
|
prepdate=$(sed -e "$item!d" -e $item's/^\((.) \)\{0,1\}\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} \)\{0,1\}.*/\2/' "$TODO_FILE")
|
||||||
prepdate=$(sed -e "$item!d" -e "${item}s/${priAndDateExpr}.*/\\2/" "$TODO_FILE")
|
|
||||||
|
|
||||||
if [ "$prepdate" -a "$action" = "replace" ] && [ "$(echo "$input"|sed -e "s/${priAndDateExpr}.*/\\1\\2/")" ]; then
|
if [ "$prepdate" -a "$action" = "replace" ] && [ "$(echo "$input"|sed -e 's/^\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\}\)\{0,1\}.*/\1/')" ]; then
|
||||||
# If the replaced text starts with a [priority +] date, it will replace
|
# If the replaced text starts with a date, it will replace the existing
|
||||||
# the existing date, too.
|
# date, too.
|
||||||
prepdate=
|
prepdate=
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Temporarily remove any existing priority and prepended date, perform the
|
# Temporarily remove any existing priority and prepended date, perform the
|
||||||
# change (replace/prepend) and re-insert the existing priority and prepended
|
# change (replace/prepend) and re-insert the existing priority and prepended
|
||||||
# date again.
|
# date again.
|
||||||
cleaninput "for sed"
|
|
||||||
sed -i.bak -e "$item s/^${priority}${prepdate}//" -e "$item s|^.*|${priority}${prepdate}${input}${backref}|" "$TODO_FILE"
|
sed -i.bak -e "$item s/^${priority}${prepdate}//" -e "$item s|^.*|${priority}${prepdate}${input}${backref}|" "$TODO_FILE"
|
||||||
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
if [ $TODOTXT_VERBOSE -gt 0 ]; then
|
||||||
getNewtodo "$item"
|
getNewtodo "$item"
|
||||||
@@ -1305,18 +1300,6 @@ note: PRIORITY must be anywhere from A to Z."
|
|||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"listaddons" )
|
|
||||||
if [ -d "$TODO_ACTIONS_DIR" ]; then
|
|
||||||
cd "$TODO_ACTIONS_DIR" || exit $?
|
|
||||||
for action in *
|
|
||||||
do
|
|
||||||
if [ -f "$action" -a -x "$action" ]; then
|
|
||||||
echo "$action"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
|
|
||||||
* )
|
* )
|
||||||
usage;;
|
usage;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
@@ -11,14 +11,18 @@ _todo()
|
|||||||
local -r OPTS="-@ -@@ -+ -++ -d -f -h -p -P -PP -a -n -t -v -vv -V -x"
|
local -r OPTS="-@ -@@ -+ -++ -d -f -h -p -P -PP -a -n -t -v -vv -V -x"
|
||||||
local -r COMMANDS="\
|
local -r COMMANDS="\
|
||||||
add a addto addm append app archive command del \
|
add a addto addm append app archive command del \
|
||||||
rm depri dp do help list ls listaddons listall lsa listcon \
|
rm depri dp do help list ls listall lsa listcon \
|
||||||
lsc listfile lf listpri lsp listproj lsprj move \
|
lsc listfile lf listpri lsp listproj lsprj move \
|
||||||
mv prepend prep pri p replace report shorthelp"
|
mv prepend prep pri p replace report shorthelp"
|
||||||
|
|
||||||
|
# Add custom commands from add-ons, if installed.
|
||||||
|
# TODO: Filter for executable flag of files found in $TODO_ACTIONS_DIR.
|
||||||
|
local allCommands="$COMMANDS $('ls' "${TODO_ACTIONS_DIR:-$HOME/.todo.actions.d}/" 2>/dev/null)"
|
||||||
|
|
||||||
local _todo_sh=${_todo_sh:-todo.sh}
|
local _todo_sh=${_todo_sh:-todo.sh}
|
||||||
local completions
|
local completions
|
||||||
if [ $COMP_CWORD -eq 1 ]; then
|
if [ $COMP_CWORD -eq 1 ]; then
|
||||||
completions="$COMMANDS $(eval TODOTXT_VERBOSE=0 $_todo_sh command listaddons) $OPTS"
|
completions="$allCommands $OPTS"
|
||||||
elif [[ $COMP_CWORD -gt 2 && ( \
|
elif [[ $COMP_CWORD -gt 2 && ( \
|
||||||
"${COMP_WORDS[COMP_CWORD-2]}" =~ ^(move|mv)$ || \
|
"${COMP_WORDS[COMP_CWORD-2]}" =~ ^(move|mv)$ || \
|
||||||
"${COMP_WORDS[COMP_CWORD-3]}" =~ ^(move|mv)$ ) ]]; then
|
"${COMP_WORDS[COMP_CWORD-3]}" =~ ^(move|mv)$ ) ]]; then
|
||||||
@@ -30,7 +34,7 @@ _todo()
|
|||||||
completions=$COMMANDS;;
|
completions=$COMMANDS;;
|
||||||
addto|listfile|lf)
|
addto|listfile|lf)
|
||||||
completions=$(eval TODOTXT_VERBOSE=0 $_todo_sh command listfile);;
|
completions=$(eval TODOTXT_VERBOSE=0 $_todo_sh command listfile);;
|
||||||
-*) completions="$COMMANDS $(eval TODOTXT_VERBOSE=0 $_todo_sh command listaddons) $OPTS";;
|
-*) completions="$allCommands $OPTS";;
|
||||||
*) case "$cur" in
|
*) case "$cur" in
|
||||||
+*) completions=$(eval TODOTXT_VERBOSE=0 $_todo_sh command listproj)
|
+*) completions=$(eval TODOTXT_VERBOSE=0 $_todo_sh command listproj)
|
||||||
COMPREPLY=( $( compgen -W "$completions" -- $cur ))
|
COMPREPLY=( $( compgen -W "$completions" -- $cur ))
|
||||||
@@ -58,7 +62,7 @@ _todo()
|
|||||||
# a safety check of the ls action output.
|
# a safety check of the ls action output.
|
||||||
local todo=$( \
|
local todo=$( \
|
||||||
eval TODOTXT_VERBOSE=0 $_todo_sh '-@ -+ -p -x command ls "^ *${cur} "' | \
|
eval TODOTXT_VERBOSE=0 $_todo_sh '-@ -+ -p -x command ls "^ *${cur} "' | \
|
||||||
sed -e 's/^ *[0-9]\{1,\} //' -e 's/\((.) \)[0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} /\1/' \
|
sed -e 's/^ *[0-9]\+ //' -e 's/\((.) \)[0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} /\1/' \
|
||||||
-e 's/\([xX] \)\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} \)\{1,2\}/\1/' \
|
-e 's/\([xX] \)\([0-9]\{2,4\}-[0-9]\{2\}-[0-9]\{2\} \)\{1,2\}/\1/' \
|
||||||
-e 's/[[:space:]]*$//' \
|
-e 's/[[:space:]]*$//' \
|
||||||
-e '1q' \
|
-e '1q' \
|
||||||
|
|||||||
Reference in New Issue
Block a user