Skip to content

Commit

Permalink
Add autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
baopham committed Jun 10, 2017
1 parent 9e695f0 commit 2fa9019
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Table of Content
* [Remove](#remove)
* [Requirements](#requirements)
* [Install](#install)
* [Autocomplete](#autocomplete)
* [Test](#test)
* [License](#license)
* [Author](#author)
Expand Down Expand Up @@ -117,6 +118,18 @@ export GOPATH=$HOME/Projects/Go
export PATH=$PATH:/usr/local/opt/go/libexec/bin:$GOPATH/bin
```

Autocomplete
-----------

To have autocomplete enabled, source [snip_bash_autocomplete](autocomplete/snip_bash_autocomplete) or [snip_zsh_autocomplete](autocomplete/snip_zsh_autocomplete).
E.g. copy one of these (depending on your shell) to `/local/path` and then add the below to your `.bashrc` or `.zhsrc`:

```bash
source /local/path/snip_bash_autocomplete
# Or
source /local/path/snip_zsh_autocomplete
```

Test
----

Expand Down
16 changes: 16 additions & 0 deletions autocomplete/snip_bash_autocomplete
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#! /bin/bash

: ${PROG:=snip}

_cli_bash_autocomplete() {
local cur opts base
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion )
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
}

complete -F _cli_bash_autocomplete $PROG

unset PROG
5 changes: 5 additions & 0 deletions autocomplete/snip_zsh_autocomplete
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
autoload -U compinit && compinit
autoload -U bashcompinit && bashcompinit

script_dir=$GOPATH/src/github.com/baopham/snip/autocomplete
source ${script_dir}/snip_bash_autocomplete

0 comments on commit 2fa9019

Please sign in to comment.