Commits

Yoshifumi YAMAGUCHI committed fd7229a Merge

Very neat!! I appreciate your cool commit!

Merged in MiCHiLU/goenv (pull request #7)

add auto-complete for the goof command

  • Participants
  • Parent commits e2f0b35, 6eae51f

Comments (0)

Files changed (1)

shellscripts/goenvwrapper.sh

 
 
 # goof_show returns all environment under $GOENVHOME
-# TODO(ymotongpoo): check existance of `activate` script.
 function _goof_show() {
   if [ `_goof_validator = 0` ] ; then
     return 1
   fi
   for dir in "$GOENVHOME"/*; do
-    if [ -d "$dir" ]; then
+    if [ -d "$dir" -a -f "$dir/activate" ]; then
       local envname=${dir##*/}
       local prefix="  "
       if [ "$envname" = "$GOENVNAME" ]; then
   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