Skip to content

Commit

Permalink
Add zsh completion
Browse files Browse the repository at this point in the history
  • Loading branch information
youyo committed Oct 18, 2019
1 parent 143a1c1 commit 9bd34f6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@ brews:
homepage: "https://github.com/youyo/awssh"
install: |
bin.install "awssh"
output = Utils.popen_read("#{bin}/awssh --completion-zsh")
(zsh_completion/"_awssh").write output
test: |
system "#{bin}/awssh --version"
1 change: 1 addition & 0 deletions awssh/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func init() {
rootCmd.Flags().Bool("select-profile", false, "select a specific profile from your credential file.")
rootCmd.Flags().Bool("cache", false, "enable cache a credentials.")
rootCmd.Flags().String("duration", "1 hour", "cache duration.")
rootCmd.Flags().Bool("completion-zsh", false, "output shell completion code for the zsh.")

viper.BindPFlags(rootCmd.Flags())
}
Expand Down
23 changes: 23 additions & 0 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,30 @@ import (
"github.com/spf13/viper"
)

const completionZshCode string = `_awssh() {
_arguments -w \
'(- *)'{-h,--help}'[show help]' \
'(-u --username)'{-u,--username}'[ssh login username.]' \
'(-p --port)'{-p,--port}'[ssh login port.]' \
'--cache[enable cache a credentials.]' \
'--duration[cache duration.]' \
'(-c --external-command)'{-c,--external-command}'[feature use.]' \
'(-i --identity-file)'{-i,--identity-file}'[identity file path.]' \
'--profile[use a specific profile from your credential file.]' \
'(-P --publickey)'{-P,--publickey}'[public key file path.]' \
'--select-profile[select a specific profile from your credential file.]' \
'--completion-zsh[output shell completion code for the zsh.]'
}
compdef _awssh awssh`

func Run(cmd *cobra.Command, args []string) (err error) {
completionZsh := viper.GetBool("completion-zsh")
if completionZsh {
cmd.Println(completionZshCode)
return nil
}

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand Down

0 comments on commit 9bd34f6

Please sign in to comment.