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.
This commit is contained in:
Ingo Karkat
2011-11-20 16:30:31 +01:00
parent d2e0f6e38d
commit 395465b5f2
3 changed files with 33 additions and 6 deletions

19
todo.sh
View File

@@ -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...]
@@ -1049,10 +1051,15 @@ case $action in
"listfile" | "lf" )
shift ## Was listfile, next $1 is file name
FILE="$1"
shift ## Was filename; next $1 is first search term
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" "$@"
_list "$FILE" "$@"
fi
;;
"listcon" | "lsc" )