Skip to content

Commit

Permalink
Added auto-complete.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryugi committed Jun 3, 2017
1 parent cc268b9 commit 76195f6
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ your `PATH`:
$ export PATH=$PATH:`pwd`/bin
```

There's also an auto-completion script you can use to get commands and
subcommands at the double-tap of the `<TAB>` key:

```
$ source resources/bash/timi-auto-complete
```


### Data Initialization [&#x219F;](#contents)

Expand Down
54 changes: 54 additions & 0 deletions resources/bash/timi-auto-complete
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# file: timi-auto-complete
# timi (sub)command-completion

TOP_LEVEL='config db -h -l -s -v --help --log-level --summary --version'
TOP_DASHED='-b -h -l -v --banner --help --log-level --summary --version'
CONFIG_LEVEL='show help'
DB_LEVEL='help init'

_timi () {
local cur prev

cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}

case ${COMP_CWORD} in
1)
case ${cur} in
-*)
COMPREPLY=($(compgen -W "${TOP_DASHED}" -- $cur ))
;;
*)
COMPREPLY=($(compgen -W "${TOP_LEVEL}" -- ${cur}))
;;
esac
;;
2)
case ${prev} in
config)
COMPREPLY=($(compgen -W "${CONFIG_LEVEL}" ${cur}))
;;
db)
COMPREPLY=($(compgen -W "${DB_LEVEL}" ${cur}))
;;
esac
;;
## If a third level of parsing is needed, uncomment below
# 3)
# case ${prev} in
# show)
# COMPREPLY=($(compgen -W "${SHOW_LEVEL}" ${cur}))
# ;;
# esac
# ;;
*)
COMPREPLY=()
;;
esac
return 0
}

complete -F _timi timi
complete -F _timi ./bin/timi
complete -F _timi `which timi`
#

0 comments on commit 76195f6

Please sign in to comment.