7649c2992631295417cbd73bb27ab07b8a91329f

Author
Robby Russell <robby@planetargon.com>
Committer
Robby Russell <robby@planetargon.com>
Date

Message

Merge pull request #2009 from akatov/grunt

grunt completion

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/grunt/grunt.plugin.zsh b/plugins/grunt/grunt.plugin.zsh
  2new file mode 100644
  3index 0000000000000000000000000000000000000000..48f6cb5a2e0abb681e4009bb693c4e863363fcb9
  4--- /dev/null
  5+++ b/plugins/grunt/grunt.plugin.zsh
  6@@ -0,0 +1,253 @@
  7+#compdef grunt
  8+# -----------------------------------------------------------------------------
  9+#  _grunt
 10+#
 11+#  Completion script for grunt.
 12+#   - https://github.com/gruntjs/grunt
 13+#   - https://github.com/gruntjs/grunt-cli
 14+#
 15+# -----------------------------------------------------------------------------
 16+#
 17+#  Version     : 0.1.0
 18+#  Author      : Yonchu <yuyuchu3333@gmail.com>
 19+#  License     : MIT License
 20+#  Repository  : https://github.com/yonchu/grunt-zsh-completion
 21+#  Last Change : 22 Jul 2013.
 22+#
 23+#  Copyright (c) 2013 Yonchu.
 24+#
 25+# -----------------------------------------------------------------------------
 26+# USAGE
 27+# -----
 28+#
 29+# Enable caching:
 30+#
 31+#   If you want to use the cache, set the followings in your .zshrc:
 32+#
 33+#     zstyle ':completion:*' use-cache yes
 34+#
 35+#
 36+# Settings:
 37+#
 38+#  - Show grunt file path:
 39+#      zstyle ':completion::complete:grunt::options:' show_grunt_path yes
 40+#
 41+#  - Cache expiration days (default: 7):
 42+#      zstyle ':completion::complete:grunt::options:' expire 1
 43+#
 44+#  - Not update options cache if target gruntfile is changed.
 45+#      zstyle ':completion::complete:grunt::options:' no_update_options yes
 46+#
 47+#  Note that if you change the zstyle settings,
 48+#  you should delete the cache file and restart zsh.
 49+#
 50+#    $ rm ~/.zcompcache/grunt
 51+#    $ exec zsh
 52+#
 53+# -----------------------------------------------------------------------------
 54+
 55+function _grunt() {
 56+    local curcontext="$curcontext" update_policy state
 57+    local show_grunt_path update_msg gruntfile opts tasks
 58+
 59+    # Setup cache-policy.
 60+    zstyle -s ":completion:${curcontext}:" cache-policy update_policy
 61+    if [[ -z $update_policy ]]; then
 62+        zstyle ":completion:${curcontext}:" cache-policy __grunt_caching_policy
 63+    fi
 64+
 65+    # Check show_path option.
 66+    zstyle -b ":completion:${curcontext}:options:" show_grunt_path show_grunt_path
 67+
 68+    # Get current gruntfile.
 69+    gruntfile=$(__grunt_get_gruntfile)
 70+
 71+    # Initialize opts and tasks.
 72+    opts=()
 73+    tasks=()
 74+
 75+    # Add help options.
 76+    opts+=('(- 1 *)'{-h,--help}'[Display this help text.]')
 77+
 78+    ## Complete without gruntfile.
 79+    if [[ ! -f $gruntfile ]]; then
 80+        _arguments "${opts[@]}"
 81+        return
 82+    fi
 83+
 84+    ## Complete with gruntfile.
 85+    # Retrieve cache.
 86+    if ! __grunt_update_cache "$gruntfile"; then
 87+        update_msg=' (cache updated)'
 88+    fi
 89+
 90+    # Make optioins completion.
 91+    if [[ ${#__grunt_opts} -gt 0 ]]; then
 92+        opts+=("${__grunt_opts[@]}")
 93+    fi
 94+
 95+    # Complete arguments.
 96+    _arguments \
 97+        "${opts[@]}" \
 98+        '*: :->tasks' \
 99+        && return
100+
101+    case $state in
102+        tasks)
103+            if [[ $show_grunt_path == 'yes' ]]; then
104+                update_msg="$update_msg: ${${gruntfile/#$HOME/~}%/}"
105+            fi