Compare commits

..

2 Commits

Author SHA1 Message Date
Ingo Karkat
cd7d2f2fda ENH: Add file completion for move. 2011-11-20 17:07:59 +01:00
Ingo Karkat
395465b5f2 ENH: Add file completion for addto and listfile.
This enhancement to todo_completion requires a small enhancement to the listfile action: When no SRC is specified, the list of text files in the todo.txt directory is printed. This is probably also useful on its own, and better than the original behavior of printing "TODO: File  does not exist."

Note: I intentionally omitted bullet-proof error handling ($TODO_DIR non-existing or no text files contained), to avoid over-complicating this.
2011-11-20 16:30:31 +01:00
3 changed files with 38 additions and 6 deletions

View File

@@ -39,6 +39,24 @@ GARDEN: 2 added.
GARDEN: 2 of 2 tasks shown GARDEN: 2 of 2 tasks shown
EOF 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 # Filter
# #

19
todo.sh
View File

@@ -57,7 +57,7 @@ shorthelp()
list|ls [TERM...] list|ls [TERM...]
listall|lsa [TERM...] listall|lsa [TERM...]
listcon|lsc listcon|lsc
listfile|lf SRC [TERM...] listfile|lf [SRC [TERM...]]
listpri|lsp [PRIORITY] [TERM...] listpri|lsp [PRIORITY] [TERM...]
listproj|lsprj [TERM...] listproj|lsprj [TERM...]
move|mv ITEM# DEST [SRC] move|mv ITEM# DEST [SRC]
@@ -211,11 +211,13 @@ help()
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.
listfile SRC [TERM...] listfile [SRC [TERM...]]
lf SRC [TERM...] lf [SRC [TERM...]]
Displays all the lines in SRC file located in the todo.txt directory, Displays all the lines in SRC file located in the todo.txt directory,
sorted by priority with line numbers. If TERM specified, lists sorted by priority with line numbers. If TERM specified, lists
all lines that contain TERM in SRC file. 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...] listpri [PRIORITY] [TERM...]
lsp [PRIORITY] [TERM...] lsp [PRIORITY] [TERM...]
@@ -1049,10 +1051,15 @@ case $action in
"listfile" | "lf" ) "listfile" | "lf" )
shift ## Was listfile, next $1 is file name shift ## Was listfile, next $1 is file name
FILE="$1" if [ $# -eq 0 ]; then
shift ## Was filename; next $1 is first search term [ $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" "$@" _list "$FILE" "$@"
fi
;; ;;
"listcon" | "lsc" ) "listcon" | "lsc" )

View File

@@ -22,10 +22,17 @@ _todo()
local completions local completions
if [ $COMP_CWORD -eq 1 ]; then if [ $COMP_CWORD -eq 1 ]; then
completions="$allCommands $OPTS" 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 else
case "$prev" in case "$prev" in
command) command)
completions=$COMMANDS;; completions=$COMMANDS;;
addto|listfile|lf)
completions=$(TODOTXT_VERBOSE=0 todo.sh command listfile);;
-*) completions="$allCommands $OPTS";; -*) completions="$allCommands $OPTS";;
*) case "$cur" in *) case "$cur" in
+*) completions=$(TODOTXT_VERBOSE=0 todo.sh command listproj);; +*) completions=$(TODOTXT_VERBOSE=0 todo.sh command listproj);;