From eb2d4a10541255dc6fe52fe5fa37834390f6fe1a Mon Sep 17 00:00:00 2001 From: sanmiguel Date: Mon, 28 Oct 2013 15:05:11 +0000 Subject: First draft of basic zsh completion --- zsh_completion/_kerl | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 zsh_completion/_kerl diff --git a/zsh_completion/_kerl b/zsh_completion/_kerl new file mode 100644 index 0000000..628b3bf --- /dev/null +++ b/zsh_completion/_kerl @@ -0,0 +1,95 @@ +#compdef kerl + +# ------------------------------------------------------------------------------ +# Description +# ----------- +# +# Completion script for kerl (http://github.com/spawngrid/kerl +# +# Source: https://github.com/sanmiguel/zsh-completions +# +# ------------------------------------------------------------------------------ +# Authors +# ------- +# +# * Michael Coles (https://github.com/sanmiguel) +# +# ------------------------------------------------------------------------------ + +# TODO: These are naive and stupid +_kerl_available_releases() { + releases=(${(f)"$(_call_program releases cat ~/.kerl/otp_releases)"}) +} + +_kerl_builds() { + builds=(${(f)"$(_call_program builds cut -f 2 -d "," ~/.kerl/otp_builds)"}) +} + +_kerl_installations() { + installations=(${(f)"$(_call_program installations kerl list installations 2>/dev/null)"}) +} + +local -a _1st_arguments +_1st_arguments=( + 'build:Build specified release or git repository' + 'install:Install the specified release at the given location' + 'deploy:Deploy the specified installation to the given host and location' + 'update:Update the list of available releases from erlang.org' + 'list:List releases, builds and installations' + 'delete:Delete builds and installations' + 'active:Print the path of the active installation' + 'status:Print available builds and installations' + 'prompt:Print a string suitable for insertion in prompt' + 'cleanup:Remove compilation artifacts (use after installation)' +) + +local -a _list_options +_list_options=( + 'releases:All available OTP releases' + 'builds:All locally built OTP releases' + 'installations:All locally installed OTP builds' +) + +local expl +local -a releases builds installations + +_arguments \ + '*:: :->subcmds' && return 0 + +if (( CURRENT == 1 )); then + _describe -t commands "kerl subcommand" _1st_arguments + return +fi + +case "$words[1]" in + build) + _arguments \ + '1: :->rels' && return 0 + + if [[ "$state" == rels ]]; then + _kerl_available_releases + _wanted releases expl 'all releases' compadd -a releases + fi;; + install) + _arguments \ + '1: :->blds' && return 0 + + if [[ "$state" == blds ]]; then + _kerl_builds + _wanted builds expl 'all builds' compadd -a builds + return + fi + _directories + ;; + deploy) _hosts;; # TODO: [directory] [remote directory] + update) _describe "kerl update options" ('releases:Update releases list');; + list) + _describe "kerl list options" _list_options + return + ;; + delete) ;; + active) ;; + status) ;; + prompt) ;; + cleanup) ;; +esac -- cgit v1.2.3 From cfeea403c1092c4e9524fe82a6a73b62b60173d6 Mon Sep 17 00:00:00 2001 From: sanmiguel Date: Wed, 20 Nov 2013 17:05:51 +0000 Subject: zsh-completion module for kerl --- zsh_completion/_kerl | 73 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 14 deletions(-) diff --git a/zsh_completion/_kerl b/zsh_completion/_kerl index 628b3bf..10ae768 100644 --- a/zsh_completion/_kerl +++ b/zsh_completion/_kerl @@ -18,15 +18,16 @@ # TODO: These are naive and stupid _kerl_available_releases() { + # we use the file directly as `kerl list releases` dumps extraneous data to stdout releases=(${(f)"$(_call_program releases cat ~/.kerl/otp_releases)"}) } _kerl_builds() { - builds=(${(f)"$(_call_program builds cut -f 2 -d "," ~/.kerl/otp_builds)"}) + builds=(${(f)"$(_call_program builds kerl list builds 2>/dev/null | cut -f 2 -d ",")"}) } _kerl_installations() { - installations=(${(f)"$(_call_program installations kerl list installations 2>/dev/null)"}) + installations=(${(f)"$(_call_program installations kerl list installations 2>/dev/null | cut -f 2 -d " ")"}) } local -a _1st_arguments @@ -49,6 +50,10 @@ _list_options=( 'builds:All locally built OTP releases' 'installations:All locally installed OTP builds' ) +local -a _update_options +_update_options=( + 'releases:All available OTP releases' +) local expl local -a releases builds installations @@ -62,34 +67,74 @@ if (( CURRENT == 1 )); then fi case "$words[1]" in + active) ;; + status) ;; + prompt) ;; build) _arguments \ - '1: :->rels' && return 0 + '1: :->rels' \ + '2: :->buildnames' && return 0 if [[ "$state" == rels ]]; then _kerl_available_releases _wanted releases expl 'all releases' compadd -a releases + elif [[ "$state" == buildnames ]]; then + fi;; + # TODO: suggest build name as $(lowercase $release) install) _arguments \ - '1: :->blds' && return 0 + '1: :->blds' \ + '2::location:_path_files -W "(~/kerl)"' && return 0 if [[ "$state" == blds ]]; then _kerl_builds _wanted builds expl 'all builds' compadd -a builds return fi + # TODO: suggest starting location of "$KERLDIR/$(lowercase $build)" _directories ;; - deploy) _hosts;; # TODO: [directory] [remote directory] - update) _describe "kerl update options" ('releases:Update releases list');; + deploy) + _arguments \ + '1: :->hosts' \ + '2: :->installs' && return 0 + + if [[ "$state" == hosts ]]; then + _hosts + return + elif [[ "$state" == installs ]]; then + _kerl_installations + _wanted installations expl 'all installations' compadd -a installations + return + fi + ;; # TODO: [remote directory] (or at least prompt) + update) + _arguments '1: :->updopts' && return 0 + if [[ "$state" == updopts ]]; then _describe "kerl update options" _update_options; fi + ;; list) - _describe "kerl list options" _list_options - return - ;; - delete) ;; - active) ;; - status) ;; - prompt) ;; - cleanup) ;; + _arguments '1: :->listopts' && return 0 + if [[ "$state" == listopts ]]; then _describe "kerl list options" _list_options; fi + ;; + delete) + _arguments \ + '1::(build installation)' && return 0 + + case "$words[2]" in + build) + _kerl_builds + _wanted builds expl 'all builds' compadd -a builds + return + ;; + installation) + _kerl_installations + _wanted installations expl 'all installations' compadd -a installations + return + esac + ;; + cleanup) + _kerl_builds + builds=('all' $builds) + _wanted builds expl 'all builds' compadd -a builds;; esac -- cgit v1.2.3 From a4b760505f16d503b0a6779ce571d8c56cb0491a Mon Sep 17 00:00:00 2001 From: sanmiguel Date: Wed, 20 Nov 2013 17:14:44 +0000 Subject: Update readme --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 833d4ff..9711e14 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,9 @@ and drop it in your $PATH Optionally download and install kerl's bash_completion file from https://github.com/spawngrid/kerl/raw/master/bash_completion/kerl +Optionally download and install kerl's zsh-completion file from https://github.com/spawngrid/kerl/raw/master/zsh_completion/\_kerl + + How it works ============ -- cgit v1.2.3 From 7552fbb6209bb9aaac5e20814ad4acf98666d6b6 Mon Sep 17 00:00:00 2001 From: sanmiguel Date: Wed, 20 Nov 2013 17:15:28 +0000 Subject: Update README.md Formatting --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9711e14..e27f029 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ and drop it in your $PATH Optionally download and install kerl's bash_completion file from https://github.com/spawngrid/kerl/raw/master/bash_completion/kerl -Optionally download and install kerl's zsh-completion file from https://github.com/spawngrid/kerl/raw/master/zsh_completion/\_kerl +Optionally download and install kerl's zsh-completion file from https://github.com/spawngrid/kerl/raw/master/zsh_completion/_kerl How it works -- cgit v1.2.3 From c548650ddfc8a12e3f1d34ed3cf498d7963ed945 Mon Sep 17 00:00:00 2001 From: sanmiguel Date: Thu, 21 Nov 2013 18:23:00 +0000 Subject: Add TODO comment for _kerl --- zsh_completion/_kerl | 1 + 1 file changed, 1 insertion(+) diff --git a/zsh_completion/_kerl b/zsh_completion/_kerl index 10ae768..e58eb8b 100644 --- a/zsh_completion/_kerl +++ b/zsh_completion/_kerl @@ -86,6 +86,7 @@ case "$words[1]" in _arguments \ '1: :->blds' \ '2::location:_path_files -W "(~/kerl)"' && return 0 + ## TODO: This path should not be hard-coded! if [[ "$state" == blds ]]; then _kerl_builds -- cgit v1.2.3