Commits

takanao ENDOH committed 6eae51f

add goof compdef for zsh

Comments (0)

Files changed (1)

shellscripts/goenvwrapper.sh

   return 0
 }
 
+# goof compdef for zsh
+_goof_compdef() {
+  local context state line
+  typeset -A opt_args
+
+  _arguments \
+    '1: :_goof_commands' \
+    '2: :->args'
+
+  case $state in
+    args)
+    case $line[1] in
+      (workon|remove)
+        _goof_workspace && return 0
+      ;;
+    esac
+    ;;
+  esac
+}
+
+_goof_commands() {
+  _values \
+    'goof commands' \
+    '(- *)make[Create a new Go workspace]' \
+    '(-)workon[Switch the environment to specified workspace]' \
+    '(-)remove[Delete a specified workspace]' \
+    '(- *)show[Show a list of existing workspaces]' \
+    '(- *)goinstall[Build and install Go binary of given version]' \
+    '(- *)go[Replace GOROOT with specified Go version binaries]'
+}
+
+_goof_workspace() {
+  local workspaces
+  workspaces=( $(\
+    (cd "$GOENVHOME" && echo */activate) 2>/dev/null \
+      | command \sed "s|/activate||g" \
+      | (unset GREP_OPTIONS; command \egrep -v '^\*$') 2>/dev/null \
+    ) )
+  compadd $workspaces
+  return 1;
+}
+
+if [ -n "$ZSH_VERSION" ]; then
+  compdef _goof_compdef goof
+fi