Skip to content

Commit

Permalink
Bash autocompletion for ddev, fixes #125 (#309)
Browse files Browse the repository at this point in the history
* Add autocomplete command build

* Add bash completion to install_ddev.sh

* Add minor doc for using autocomplete

* Generate bash completion in circle and add to tarballs

* Satisfy the static analysis gods

* Consolidate artifacts-generation in a script
  • Loading branch information
rfay committed Jun 13, 2017
1 parent 45d6cba commit 67268ed
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 53 deletions.
56 changes: 3 additions & 53 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,7 @@ jobs:
name: ddev version information

- run:
command: |
BASE_DIR=$PWD
sudo mkdir $ARTIFACTS && sudo chmod 777 $ARTIFACTS
export VERSION=$(git describe --tags --always --dirty)
cd $BASE_DIR/bin/darwin/darwin_amd64
tar -czf $ARTIFACTS/ddev_osx.$VERSION.tar.gz ddev
zip $ARTIFACTS/ddev_osx.$VERSION.zip ddev
cd $BASE_DIR/bin/linux
tar -czf $ARTIFACTS/ddev_linux.$VERSION.tar.gz ddev
zip $ARTIFACTS/ddev_linux.$VERSION.zip ddev
cd $BASE_DIR/bin/windows/windows_amd64
tar -czf $ARTIFACTS/ddev_windows.$VERSION.tar.gz ddev.exe
zip $ARTIFACTS/ddev_windows.$VERSION.zip ddev.exe
cd $ARTIFACTS
for item in *.tar.gz *.zip; do
sha256sum $item > $item.sha256.txt
done
command: ./.circleci/generate_artifacts.sh $ARTIFACTS
name: tar/zip up artifacts and make hashes

- store_artifacts:
Expand All @@ -71,8 +55,6 @@ jobs:
GOPATH: /home/circleci/go
ARTIFACTS: /artifacts
steps:
# - run: mkdir -p ~/go/{lib,pkg,src/github.com/drud/ddev}

- checkout

- run:
Expand Down Expand Up @@ -128,23 +110,7 @@ jobs:
name: ddev version information (clean binaries, not nightlies)

- run:
command: |
BASE_DIR=$PWD
sudo mkdir $ARTIFACTS && sudo chmod 777 $ARTIFACTS
export VERSION=$(git describe --tags --always --dirty)
cd $BASE_DIR/bin/darwin/darwin_amd64
tar -czf $ARTIFACTS/ddev_osx.$VERSION.tar.gz ddev
zip $ARTIFACTS/ddev_osx.$VERSION.zip ddev
cd $BASE_DIR/bin/linux
tar -czf $ARTIFACTS/ddev_linux.$VERSION.tar.gz ddev
zip $ARTIFACTS/ddev_linux.$VERSION.zip ddev
cd $BASE_DIR/bin/windows/windows_amd64
tar -czf $ARTIFACTS/ddev_windows.$VERSION.tar.gz ddev.exe
zip $ARTIFACTS/ddev_windows.$VERSION.zip ddev.exe
cd $ARTIFACTS
for item in *.tar.gz *.zip; do
sha256sum $item > $item.sha256.txt
done
command: ./.circleci/generate_artifacts.sh $ARTIFACTS
name: tar/zip up artifacts and make hashes

- store_artifacts:
Expand Down Expand Up @@ -178,23 +144,7 @@ jobs:
name: ddev version information

- run:
command: |
BASE_DIR=$PWD
sudo mkdir $ARTIFACTS && sudo chmod 777 $ARTIFACTS
export VERSION=$(git describe --tags --always --dirty)
cd $BASE_DIR/bin/darwin/darwin_amd64
tar -czf $ARTIFACTS/ddev_osx.$VERSION.tar.gz ddev
zip $ARTIFACTS/ddev_osx.$VERSION.zip ddev
cd $BASE_DIR/bin/linux
tar -czf $ARTIFACTS/ddev_linux.$VERSION.tar.gz ddev
zip $ARTIFACTS/ddev_linux.$VERSION.zip ddev
cd $BASE_DIR/bin/windows/windows_amd64
tar -czf $ARTIFACTS/ddev_windows.$VERSION.tar.gz ddev.exe
zip $ARTIFACTS/ddev_windows.$VERSION.zip ddev.exe
cd $ARTIFACTS
for item in *.tar.gz *.zip; do
sha256sum $item > $item.sha256.txt
done
command: ./.circleci/generate_artifacts.sh $ARTIFACTS
name: tar/zip up artifacts and make hashes

- store_artifacts:
Expand Down
36 changes: 36 additions & 0 deletions .circleci/generate_artifacts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

set -o errexit

ARTIFACTS=$1
BASE_DIR=$PWD

sudo mkdir $ARTIFACTS && sudo chmod 777 $ARTIFACTS
export VERSION=$(git describe --tags --always --dirty)

# Generate and place the autocomplete
bin/linux/ddev_gen_autocomplete
for dir in bin/darwin/darwin_amd64 bin/linux bin/windows/windows_amd64; do
cp bin/ddev_bash_completion.sh $dir
done

# Generate OSX tarball/zipball
cd $BASE_DIR/bin/darwin/darwin_amd64
tar -czf $ARTIFACTS/ddev_osx.$VERSION.tar.gz ddev ddev_bash_completion.sh
zip $ARTIFACTS/ddev_osx.$VERSION.zip ddev ddev_bash_completion.sh

# Generate linux tarball/zipball
cd $BASE_DIR/bin/linux
tar -czf $ARTIFACTS/ddev_linux.$VERSION.tar.gz ddev ddev_bash_completion.sh
zip $ARTIFACTS/ddev_linux.$VERSION.zip ddev ddev_bash_completion.sh

# generate windows tarball/zipball
cd $BASE_DIR/bin/windows/windows_amd64
tar -czf $ARTIFACTS/ddev_windows.$VERSION.tar.gz ddev.exe ddev_bash_completion.sh
zip $ARTIFACTS/ddev_windows.$VERSION.zip ddev.exe ddev_bash_completion.sh

# Create the sha256 files
cd $ARTIFACTS
for item in *.tar.gz *.zip; do
sha256sum $item > $item.sha256.txt
done
20 changes: 20 additions & 0 deletions cmd/ddev_gen_autocomplete/ddev_gen_autocomplete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
"os"
"path/filepath"

"github.com/drud/ddev/cmd/ddev/cmd"
"github.com/drud/ddev/pkg/util"
)

var targetDir = "bin"

func main() {
if _, err := os.Stat(targetDir); os.IsNotExist(err) {
err = os.MkdirAll(targetDir, 0755)
util.CheckErr(err)
}
err := cmd.RootCmd.GenBashCompletionFile(filepath.Join(targetDir, "ddev_bash_completion.sh"))
util.CheckErr(err)
}
3 changes: 3 additions & 0 deletions docs/users/cli-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,6 @@ You can stop a site's containers without losing data by using `ddev stop` in the

## Removing a site
You can remove a site's containers by running `ddev remove` in the working directory of the site. You can also remove any running site's containers by providing the site name as an argument, e.g. `ddev remove <sitename>`. **Note:** `ddev remove` is destructive. It will remove all containers for the site, destroying database contents in the process. Your project code base and files will not be affected.

## ddev Command Auto-Completion
ddev bash auto-completion is available. If you have installed ddev via homebrew (on OSX) it will already be installed. Otherwise, you can download the [latest release](https://github.com/drud/ddev/releases) tarball for your platform and the ddev_bash_completions.sh inside it can be installed wherever your bash_completions.d is. For example, `cp ddev_bash_completions.sh /etc/bash_completion.d/ddev`
9 changes: 9 additions & 0 deletions install_ddev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ else
sudo mv /tmp/ddev /usr/local/bin/
fi

if which brew && [ -f `brew --prefix`/etc/bash_completion ]; then
bash_completion_dir=$(brew --prefix)/etc/bash_completion.d
cp /tmp/ddev_bash_completion.sh $bash_completion_dir/ddev
echo "$(GREEN)Installed ddev bash completions in $bash_completion_dir$(RESET)"
rm /tmp/ddev_bash_completion.sh
else
echo "$(YELLOW)Bash completion for ddev was not installed. You may manually install /tmp/ddev_bash_completions.sh in your bash_completions.d directory.$(RESET)"
fi

rm /tmp/$TARBALL /tmp/$SHAFILE

echo "${GREEN}ddev is now installed. Run \"ddev\" to verify your installation and see usage.${RESET}"

0 comments on commit 67268ed

Please sign in to comment.