-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
139 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,5 @@ build | |
dist | ||
key.* | ||
*.asc | ||
|
||
completions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#! /bin/bash | ||
|
||
# Macs have bash3 for which the bash-completion package doesn't include | ||
# _init_completion. This is a minimal version of that function. | ||
_cli_init_completion() { | ||
COMPREPLY=() | ||
_get_comp_words_by_ref "$@" cur prev words cword | ||
} | ||
|
||
_cli_bash_autocomplete() { | ||
if [[ "${COMP_WORDS[0]}" != "source" ]]; then | ||
local cur opts base words | ||
COMPREPLY=() | ||
cur="${COMP_WORDS[COMP_CWORD]}" | ||
if declare -F _init_completion >/dev/null 2>&1; then | ||
_init_completion -n "=:" || return | ||
else | ||
_cli_init_completion -n "=:" || return | ||
fi | ||
words=("${words[@]:0:$cword}") | ||
if [[ "$cur" == "-"* ]]; then | ||
requestComp="${words[*]} ${cur} --generate-bash-completion" | ||
else | ||
requestComp="${words[*]} --generate-bash-completion" | ||
fi | ||
opts=$(eval "${requestComp}" 2>/dev/null) | ||
COMPREPLY=($(compgen -W "${opts}" -- ${cur})) | ||
return 0 | ||
fi | ||
} | ||
|
||
complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete spacectl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package completion | ||
|
||
import ( | ||
"bytes" | ||
_ "embed" | ||
"io" | ||
"os" | ||
"strings" | ||
|
||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
var ( | ||
//go:embed bash_autocomplete | ||
bashAutocomplete []byte | ||
|
||
//go:embed zsh_autocomplete | ||
zshAutocomplete []byte | ||
) | ||
|
||
func Command() *cli.Command { | ||
return &cli.Command{ | ||
Name: "completion", | ||
Usage: "Print out shell completion script", | ||
Subcommands: []*cli.Command{ | ||
{ | ||
Name: "bash", | ||
Usage: "Print out bash shell completion script", | ||
Action: func(cliCtx *cli.Context) error { | ||
_, err := io.Copy(os.Stdout, bytes.NewReader(bashAutocomplete)) | ||
return err | ||
}, | ||
}, | ||
{ | ||
Name: "zsh", | ||
Usage: "Print out zsh shell completion script", | ||
Action: func(cliCtx *cli.Context) error { | ||
_, err := io.Copy(os.Stdout, bytes.NewReader(zshAutocomplete)) | ||
return err | ||
}, | ||
}, | ||
{ | ||
Name: "fish", | ||
Usage: "Print out fish shell completion script", | ||
Action: func(cliCtx *cli.Context) error { | ||
s, err := cliCtx.App.ToFishCompletion() | ||
if err != nil { | ||
return err | ||
} | ||
_, err = io.Copy(os.Stdout, strings.NewReader(s)) | ||
return err | ||
}, | ||
}, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#compdef spacectl | ||
|
||
_cli_zsh_autocomplete() { | ||
local -a opts | ||
local cur | ||
cur=${words[-1]} | ||
if [[ "$cur" == "-"* ]]; then | ||
opts=("${(@f)$(${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}") | ||
else | ||
opts=("${(@f)$(${words[@]:0:#words[@]-1} --generate-bash-completion)}") | ||
fi | ||
|
||
if [[ "${opts[1]}" != "" ]]; then | ||
_describe 'values' opts | ||
else | ||
_files | ||
fi | ||
} | ||
|
||
compdef _cli_zsh_autocomplete spacectl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
rm -rf completions | ||
mkdir completions | ||
|
||
for sh in bash zsh fish; do | ||
go run main.go completion "$sh" >"completions/spacectl.$sh" | ||
done |