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..7f3d391 100644 --- a/todo_completion +++ b/todo_completion @@ -22,10 +22,17 @@ _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) 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);;