Avoid leaking internal variables into the shell + robustness against add-ons.

Use "local" to avoid that the internal completion variables are accessible from the user's shell.
Use "todo.sh command" for the context/project lookups to avoid interference with custom add-ons of the same name, and reset TODOTXT_VERBOSE to avoid adding any message output (currently there is none).
This commit is contained in:
Ingo Karkat
2011-11-20 14:36:44 +01:00
parent 285d5039f2
commit 8cba7533b9

View File

@@ -7,25 +7,33 @@ _todo()
COMPREPLY=() COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}" cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}" prev="${COMP_WORDS[COMP_CWORD-1]}"
COMMANDS="add a addto addm append app archive command del \
rm depri dp do help list ls listall lsa listcon \ local -r OPTS="-@ -@@ -+ -++ -d -f -h -p -P -PP -a -n -t -v -vv -V -x"
lsc listfile lf listpri lsp listproj lsprj move \ local -r COMMANDS="\
mv prepend prep pri p replace report" 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"
# Add custom commands from add-ons, if installed. # Add custom commands from add-ons, if installed.
COMMANDS="$COMMANDS $('ls' ${TODO_ACTIONS_DIR:-$HOME/.todo.actions.d}/ 2>/dev/null)" local allCommands="$COMMANDS $('ls' ${TODO_ACTIONS_DIR:-$HOME/.todo.actions.d}/ 2>/dev/null)"
OPTS="-@ -@@ -+ -++ -d -f -h -p -P -PP -a -n -t -v -vv -V -x"
if [ "${cur:0:1}" == "+" ]; then local completions
completions="$(todo.sh listproj)" if [ $COMP_CWORD -eq 1 ]; then
elif [ "${cur:0:1}" == "@" ]; then completions="$allCommands $OPTS"
completions="$(todo.sh listcon)"
elif [ $COMP_CWORD -eq 1 ]; then
completions="$COMMANDS $OPTS"
else else
case "${prev}" in case "$prev" in
-*) completions="$COMMANDS $OPTS";; command)
*) return 0;; completions=$COMMANDS;;
-*) completions="$allCommands $OPTS";;
*) case "$cur" in
+*) completions=$(TODOTXT_VERBOSE=0 todo.sh command listproj);;
@*) completions=$(TODOTXT_VERBOSE=0 todo.sh command listcon);;
*) return 0;;
esac
esac esac
fi fi
COMPREPLY=( $( compgen -W "$completions" -- $cur )) COMPREPLY=( $( compgen -W "$completions" -- $cur ))
return 0 return 0
} }