From f09b640e90015dc559af1d6c45d2570940d56b7c Mon Sep 17 00:00:00 2001 From: ngtuna Date: Sun, 17 Jul 2016 02:21:15 +0700 Subject: [PATCH] support bash completion for commands, not for flags --- README.md | 7 +++++++ cli/main/main.go | 1 + script/bash_autocomplete | 14 ++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 script/bash_autocomplete diff --git a/README.md b/README.md index d34c0cf9..9f3bc687 100755 --- a/README.md +++ b/README.md @@ -181,6 +181,13 @@ WARNING: Unsupported key ContainerName - ignoring WARNING: Unsupported key Dockerfile - ignoring ``` +## Bash completion +Running this below command in order to benefit from bash completion + +``` +$ PROG=kompose source script/bash_autocomplete +``` + ## Building ### Building with `go` diff --git a/cli/main/main.go b/cli/main/main.go index baaa19fe..d0f309f6 100644 --- a/cli/main/main.go +++ b/cli/main/main.go @@ -35,6 +35,7 @@ func main() { app.Version = version.VERSION + " (" + version.GITCOMMIT + ")" app.Author = "Skippbox Compose Contributors" app.Email = "https://github.com/skippbox/kompose" + app.EnableBashCompletion = true app.Before = cliApp.BeforeApp app.Flags = append(command.CommonFlags()) app.Commands = []cli.Command{ diff --git a/script/bash_autocomplete b/script/bash_autocomplete new file mode 100644 index 00000000..21a232f1 --- /dev/null +++ b/script/bash_autocomplete @@ -0,0 +1,14 @@ +#! /bin/bash + +: ${PROG:=$(basename ${BASH_SOURCE})} + +_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