Update completion.
@@ -6,16 +6,7 @@ __law_complete() {
db_file="$HOME/.law/db"
fi
- local cur="${COMP_WORDS[COMP_CWORD]}"
-
- if [ "$COMP_CWORD" -gt "1" ] && [ "${COMP_WORDS[1]}" != "run" ]; then
- return
- fi
-
- if [ "$COMP_CWORD" -gt "2" ]; then
- local task_family="${COMP_WORDS[2]}"
- fi
-
+ # cross-OS grep
_grep() {
if [ "$( uname -s )" != "Darwin" ]; then
grep -Po $@
@@ -24,14 +15,29 @@ __law_complete() {
fi
}
- case $COMP_CWORD in
- 1)
+ local cur="${COMP_WORDS[COMP_CWORD]}"
+
+ # trivial case
+ if [ "$COMP_CWORD" = "0" ]; then
+ return
+ fi
+
+ # complete the subcommand
+ if [ "$COMP_CWORD" = "1" ]; then
COMPREPLY=( $( compgen -W "run db completion" "${cur}" ) )
- ;;
- 2)
+ return
+ fi
+
+ # complete run
+ if [ "${COMP_WORDS[1]}" = "run" ]; then
+ # task family
+ if [ "$COMP_CWORD" = "2" ]; then
COMPREPLY=( $( compgen -W "$( _grep "[^\:]+\:\K(.+)(?=\:.+)" "$db_file" )" "${cur}" ) )
- ;;
- *)
+ return
+ fi
+ local task_family="${COMP_WORDS[2]}"
+
+ # parameters
local inp="${cur##-}"
inp="${inp##-}"
COMPREPLY=( $( compgen -W "$( _grep "[^\:]+\:$task_family\:\K.+" "$db_file" )" -P "--" -- "$inp" ) )
@@ -61,8 +67,7 @@ __law_complete() {
fi
fi
- ;;
- esac
+ fi
}
export -f __law_complete
