Skip to content

CP-1122 Bash completions #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions tool/ddev-completion.sh
Original file line number Diff line number Diff line change
@@ -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