From 395465b5f2def592e5f763a21dee2580146a8399 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Sun, 20 Nov 2011 16:30:31 +0100 Subject: [PATCH 1/2] 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. --- tests/t1020-addtolistfile.sh | 18 ++++++++++++++++++ todo.sh | 19 +++++++++++++------ todo_completion | 2 ++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/tests/t1020-addtolistfile.sh b/tests/t1020-addtolistfile.sh index 42cad3c..4ddea44 100755 --- a/tests/t1020-addtolistfile.sh +++ b/tests/t1020-addtolistfile.sh @@ -39,6 +39,24 @@ GARDEN: 2 added. GARDEN: 2 of 2 tasks shown EOF +# +# List available files +# +test_todo_session 'list available files' <>> 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 # diff --git a/todo.sh b/todo.sh index c2fa85c..9351e38 100755 --- a/todo.sh +++ b/todo.sh @@ -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" ) diff --git a/todo_completion b/todo_completion index c80fba5..7e6bbe6 100644 --- a/todo_completion +++ b/todo_completion @@ -26,6 +26,8 @@ _todo() case "$prev" in command) completions=$COMMANDS;; + addto|listfile|lf) + completions=$(TODOTXT_VERBOSE=0 todo.sh command listfile);; -*) completions="$allCommands $OPTS";; *) case "$cur" in +*) completions=$(TODOTXT_VERBOSE=0 todo.sh command listproj);; From cd7d2f2fda96bb6733c5c43e4b69cd11c26f76c1 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Sun, 20 Nov 2011 17:07:59 +0100 Subject: [PATCH 2/2] ENH: Add file completion for move. --- todo_completion | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/todo_completion b/todo_completion index 7e6bbe6..7f3d391 100644 --- a/todo_completion +++ b/todo_completion @@ -22,6 +22,11 @@ _todo() local completions if [ $COMP_CWORD -eq 1 ]; then 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 case "$prev" in command)