diff --git a/README.md b/README.md index b7f51ed4..15974ee3 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,26 @@ Add the following to your bash or zsh profile for convenience: alias ddev='pub run dart_dev' ``` +#### Bash Completion + +Symlink or copy the file `tool/ddev-completion.sh` into +`/etc/bash_completion.d/` (or wherever your completion scripts live, if you +have installed Bash through Homebrew on a Mac, for instance, this will be +`/usr/local/etc/bash_completion.d/`). + +If you are using Bash installed through Homebrew, you'll also need to install +the completion machinery with `brew install bash-completion`. Then make sure +something like the following is in your `.bashrc` file: + +``` +if [ -f $(brew --prefix)/etc/bash_completion ]; then + . $(brew --prefix)/etc/bash_completion +fi +``` + +Next time you load a Bash session you'll have basic completions for the `ddev` +alias described above. + #### Configuration In order to configure `dart_dev` for a specific project, run `ddev init` or `pub run dart_dev init` to generate the configuration file. This should create a diff --git a/tool/ddev-completion.sh b/tool/ddev-completion.sh new file mode 100755 index 00000000..532f34e7 --- /dev/null +++ b/tool/ddev-completion.sh @@ -0,0 +1,43 @@ +_ddev() +{ + local cur prev cmds + + COMPREPLY=() + + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + cmds="--help --quiet --version --color --no-color analyze copy-license coverage docs examples format init test" + + # + # Complete subcommand options instead of top-level commands and options. + # + + if [[ " ${COMP_WORDS[*]} " == *" analyze "* ]]; then + cmds="--help --fatal-warnings --no-fatal-warnings --hints --no-hints" + fi + + if [[ " ${COMP_WORDS[*]} " == *" coverage "* ]]; then + cmds="--help --unit --no-unit --integration --no-integration --html --no-html --open --no-open" + fi + + if [[ " ${COMP_WORDS[*]} " == *" docs "* ]]; then + cmds="--help --open --no-open" + fi + + if [[ " ${COMP_WORDS[*]} " == *" examples "* ]]; then + cmds="--help --hostname --port" + fi + + if [[ " ${COMP_WORDS[*]} " == *" format "* ]]; then + cmds="--help --check --line-length" + fi + + if [[ " ${COMP_WORDS[*]} " == *" test "* ]]; then + cmds="--help --unit --no-unit --integration --no-integration --concurrency --platform" + fi + + COMPREPLY=($(compgen -W "${cmds}" -- ${cur})) + return 0 +} +complete -F _ddev ddev +