Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1012 from daxmc99/bash_complete
Browse files Browse the repository at this point in the history
Add bash/zsh completion
  • Loading branch information
StrongMonkey authored Jun 3, 2020
2 parents d54224f + 92827dc commit ba0009c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
21 changes: 21 additions & 0 deletions cli/autocomplete/bash_autocomplete
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#! /bin/bash

: ${PROG:=$(basename ${BASH_SOURCE})}

_cli_bash_autocomplete() {
if [[ "${COMP_WORDS[0]}" != "source" ]]; then
local cur opts base
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
if [[ "$cur" == "-"* ]]; then
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} ${cur} --generate-bash-completion )
else
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion )
fi
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi
}

complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete $PROG
unset PROG
13 changes: 13 additions & 0 deletions cli/autocomplete/zsh_autocomplete
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#compdef $PROG

_cli_zsh_autocomplete() {

local -a opts
opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} --generate-bash-completion)}")

_describe 'values' opts

return
}

compdef _cli_zsh_autocomplete $PROG
1 change: 1 addition & 0 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func main() {
app.Name = appName
app.Usage = "Containers made simple, as they should be"
app.Version = fmt.Sprintf("%s (%s)", version.Version, version.GitCommit)
app.EnableBashCompletion = true
cli.VersionPrinter = func(c *cli.Context) {
fmt.Printf("%s version %s\n", app.Name, app.Version)
}
Expand Down

0 comments on commit ba0009c

Please sign in to comment.