diff options
author | xero <x@xero.nu> | 2015-04-18 14:37:59 -0400 |
---|---|---|
committer | xero <x@xero.nu> | 2015-04-18 14:37:59 -0400 |
commit | 57a1c829609c04ff382f8a94327db629f917b3a5 (patch) | |
tree | 627fd3ac82a88f9f4ac2bf80d04e2c3682e9a98e /zsh | |
parent | c2470791e31fa2952644e26c52ff1f956f03d41b (diff) | |
download | dotfiles_ascii-57a1c829609c04ff382f8a94327db629f917b3a5.tar.xz dotfiles_ascii-57a1c829609c04ff382f8a94327db629f917b3a5.zip |
setup zsh autocompletion for a few custom apps
Diffstat (limited to 'zsh')
-rwxr-xr-x | zsh/.zsh/autocompletion.zsh | 2 | ||||
-rw-r--r-- | zsh/.zsh/completion/_bower | 135 | ||||
-rw-r--r-- | zsh/.zsh/completion/_cmake | 274 | ||||
-rw-r--r-- | zsh/.zsh/completion/_composer | 76 | ||||
-rw-r--r-- | zsh/.zsh/completion/_docker | 514 | ||||
-rw-r--r-- | zsh/.zsh/completion/_hub | 160 | ||||
-rw-r--r-- | zsh/.zsh/completion/_node | 66 | ||||
-rw-r--r-- | zsh/.zsh/completion/_nvm | 85 |
8 files changed, 1311 insertions, 1 deletions
diff --git a/zsh/.zsh/autocompletion.zsh b/zsh/.zsh/autocompletion.zsh index 273e604..15ef28c 100755 --- a/zsh/.zsh/autocompletion.zsh +++ b/zsh/.zsh/autocompletion.zsh @@ -17,7 +17,7 @@ #█▓▒░ autocompletion systems autoload -Uz compinit compinit - +autoload -U ~/.zsh/completion/*(:t) zstyle ':completion:*' auto-description 'specify: %d' zstyle ':completion:*' completer _expand _complete _correct _approximate zstyle ':completion:*' format 'Completing %d' diff --git a/zsh/.zsh/completion/_bower b/zsh/.zsh/completion/_bower new file mode 100644 index 0000000..aede57c --- /dev/null +++ b/zsh/.zsh/completion/_bower @@ -0,0 +1,135 @@ +#compdef bower +# ------------------------------------------------------------------------------ +# Description +# ----------- +# +# Completion script for Bower (http://bower.io). +# +# ------------------------------------------------------------------------------ +# Authors +# ------- +# +# * Joe Lencioni (https://github.com/lencioni) +# +# ------------------------------------------------------------------------------ + + +local curcontext="$curcontext" state line _packages _opts ret=1 + +_arguments -C -A "-v" -A "--version" \ + '(- 1 *)'{-v,--version}'[display version information]' \ + '1: :->cmds' \ + '*:: :->args' && ret=0 + +case $state in + cmds) + _values "bower command" \ + "cache[Manage bower cache]" \ + "help[Display help information about Bower]" \ + "home[Opens a package homepage into your favorite browser]" \ + "info[Info of a particular package]" \ + "init[Interactively create a bower.json file]" \ + "install[Install a package locally]" \ + "link[Symlink a package folder]" \ + "list[List local packages]" \ + "lookup[Look up a package URL by name]" \ + "prune[Removes local extraneous packages]" \ + "register[Register a package]" \ + "search[Search for a package by name]" \ + "update[Update a local package]" \ + "uninstall[Remove a local package]" \ + "version[Bump a package version]" + _arguments \ + '(--force)--force[Makes various commands more forceful]' \ + '(--json)--json[Output consumable JSON]' \ + '(--log-level)--log-level[What level of logs to report]' \ + '(--offline)--offline[Do not hit the network]' \ + '(--quiet)--quiet[Only output important information]' \ + '(--silent)--silent[Do not output anything, besides errors]' \ + '(--verbose)--verbose[Makes output more verbose]' \ + '(--allow-root)--allow-root[Allows running commands as root]' + ret=0 + ;; + args) + case $line[1] in + help) + _values 'commands' \ + 'cache' \ + 'home' \ + 'info' \ + 'init' \ + 'install' \ + 'link' \ + 'list' \ + 'lookup' \ + 'prune' \ + 'register' \ + 'search' \ + 'update' \ + 'uninstall' \ + 'version' + ret=0 + ;; + (home|info|init|link|lookup|prune|register|search) + _arguments \ + '(--help)--help[Show help message]' + ret=0 + ;; + install) + _arguments \ + '(--force-latest)--force-latest[Force latest version on conflict]' \ + '(--help)--help[Show help message]' \ + '(--production)--production[Do not install project devDependencies]' \ + '(--save)--save[Save installed packages into the project''s bower.json dependencies]' \ + '(--save-dev)--save-dev[Save installed packages into the project''s bower.json devDependencies]' + ret=0 + ;; + list) + _arguments \ + '(--help)--help[Show help message]' \ + '(--paths)--paths[Generate a simple JSON source mapping]' \ + '(--relative)--relative[Make paths relative to the directory config property, which defaults to bower_components]' + ret=0 + ;; + uninstall) + _arguments \ + '(--help)--help[Show help message]' \ + '(--save)--save[Save installed packages into th projects''s bower.json dependencies]' \ + '(--save-dev)--save-dev[Save installed packages into th projects''s bower.json devDependencies]' + ret=0 + ;; + update) + _arguments \ + '(--force-latest)--force-latest[Force latest version on conflict]' \ + '(--help)--help[Show help message]' \ + '(--production)--production[Do not install project devDependencies]' + ret=0 + ;; + version) + _arguments \ + '(--message)--message[Custom git commit and tag message]' + ret=0 + ;; + exec) + _normal && ret=0 + ;; + *) + _opts=( $(bower help $line[1] | sed -e '/^ \[-/!d; s/^ \[\(-[^=]*\)=.*/\1/') ) + _opts+=( $(bower help $line[1] | sed -e '/^ -/!d; s/^ \(-.\), \[\(-[^=]*\)=.*/\1 \2/') ) + if [[ $_opts != "" ]]; then + _values 'options' $_opts && ret=0 + fi + ;; + esac + ;; +esac + +return ret + +# Local Variables: +# mode: Shell-Script +# sh-indentation: 2 +# indent-tabs-mode: nil +# sh-basic-offset: 2 +# End: +# vim: ft=zsh sw=2 ts=2 et diff --git a/zsh/.zsh/completion/_cmake b/zsh/.zsh/completion/_cmake new file mode 100644 index 0000000..544137b --- /dev/null +++ b/zsh/.zsh/completion/_cmake @@ -0,0 +1,274 @@ +#compdef cmake + +# Description +# ----------- +# +# Completion script for CMake (http://www.cmake.org). +# +# ------------------------------------------------------------------------- +# Authors +# ------- +# +# * Scott M. Kroll <skroll@gmail.com> +# +# ------------------------------------------------------------------------- +# Notes +# ----- +# +# * By default only C and C++ languages are supported for compiler flag +# variables. To define your own list of languages: +# +# cmake_langs=('C' 'C' +# 'CXX' 'C++') +# zstyle ':completion:*:cmake:*' languages $cmake_langs +# +# ------------------------------------------------------------------------- + +_cmake() { + local context state line curcontext="$curcontext" cmake_args + + local cmake_help_actions;cmake_help_actions=( + '(- 1)--help-command[Print help for a single command and exit]:command-name:_cmake_command_names' + '(- 1)--help-command-list[List available listfile commands and exit]' + '(- 1)--help-commands[Print help for all commands and exit]' + '(- 1)--help-compatcommands[Print help for compatibility commands]' + '(- 1)--help-module[Print help for compatibility commands]:module-name:_cmake_module_names' + '(- 1)--help-module-list[Print help for a single module and exit]' + '(- 1)--help-modules[Print help for all modules and exit]' + '(- 1)--help-property[List available properties and exit]:property-name:_cmake_property_names' + '(- 1)--help-property-list[List available properties and exit]' + '(- 1)--help-properties[Print help for all properties and exit]' + '(- 1)--help-variable[Print help for a single variable and exit]:variable-name:_cmake_variable_names' + '(- 1)--help-variable-list[List documented variables and exit]' + '(- 1)--help-variables[Print help for all variables and exit]' + '(- 1)--copyright[Print the CMake copyright and exit]' + '(- 1)'{--help,-help,-usage,-h,-H}'[Print usage information and exit]' + '(- 1)--help-full[Print full help and exit]' + '(- 1)--help-html[Print full help in HTML format]' + '(- 1)--help-man[Print full help as a UNIX man page and exit]' + '(- 1)'{--version,-version}'[Print full help as a UNIX man page and exit]' + ) + + local cmake_build_options;cmake_build_options=( + '-C[Pre-load a script to populate the cache]:script:_files' + '*-D-[Create a cmake cache entry]:property:_cmake_define_property' + '-U[Remove matching entries from CMake cache]:globbing expression' + '-G[Specify a makefile generator]:generator:_cmake_generators' + '-T[Specify toolset name if supported by generator]:toolset name' + '(-Wno-dev -Wdev)-Wno-dev[Suppress developer warnings]' + '(-Wno-dev -Wdev)-Wdev[Enable developer warnings]' + '-i[Run in wizard mode]' + '-L-[List cache variables]::_values "options" "[non-advanced cache variables]" "A[advanced cache variables]" "H[non-advanced cached variables with help]" "AH[advanced cache variables with help]"' + '--trace[Put cmake in trace mode]' + ':cmake project:_files -/' + ) + + local cmake_command_actions;cmake_command_actions=( + '-E[CMake command mode]:*:command' + ) + + _arguments -C -s \ + - help \ + "$cmake_help_actions[@]" \ + - command \ + "$cmake_command_actions[@]" \ + - build_opts \ + "$cmake_build_options[@]" && return 0 +} + +# ------------------- +# _cmake_command_names +# ------------------- +(( $+functions[_cmake_command_names] )) || +_cmake_command_names() { + local command_names; command_names=(${(f)"$($service --help-command-list 2> /dev/null)"}) + _values 'command name' ${command_names[@]:1} && return 0 +} + +# ----------------- +# _cmake_list_names +# ----------------- +(( $+functions[_cmake_list_names] )) || +_cmake_list_names() { + local command; command="$@[1]" + local desc; desc="$@[2]" + local list_names; list_names=(${(f)"$($service $command 2> /dev/null | sed -e 's/\[/\\\[/' -e 's/\]/\\\]/')"}) + + _values ${desc} ${list_names[@]:1} && return 0 +} + +# ------------------ +# _cmake_module_names +# ------------------ +(( $+functions[_cmake_module_names] )) || +_cmake_module_names() { + _cmake_list_names '--help-module-list' 'module name' && return 0 +} + +# -------------------- +# _cmake_property_names +# -------------------- +(( $+functions[_cmake_property_names] )) || +_cmake_property_names() { + _cmake_list_names '--help-property-list' 'property name' && return 0 +} + +# --------------------- +# _cmake_variable_names +# --------------------- +(( $+functions[_cmake_variable_names] )) || +_cmake_variable_names() { + _cmake_list_names '--help-variable-list' 'variable name' && return 0 +} + +# ---------------------- +# _cmake_define_property +# ---------------------- +(( $+functions[_cmake_define_property] )) || +_cmake_define_property() { + if compset -P '*='; then + _wanted property-values expl 'property value' _cmake_define_property_values ${${IPREFIX%=}#-D} && return 0 + else + _wanted property-names expl 'property name' _cmake_define_property_names -qS= && return 0 + fi +} + +# ---------------------------- +# _cmake_define_property_names +# ---------------------------- +(( $+functions[_cmake_define_property_names] )) || +_cmake_define_property_names() { + local alternatives; alternatives=( + 'common-property-names:common property name:_cmake_define_common_property_names -qS=' + ) + local -A cmake_langs + zstyle -a ":completion:${curcontext}:" languages cmake_langs + [[ $#cmake_langs -eq 0 ]] && cmake_langs=('C' 'C' 'CXX' 'C++') + + for cmake_lang in ${(k)cmake_langs}; do + cmake_lang_desc="${cmake_langs[$cmake_lang]}" + alternatives+=("${cmake_lang//:/-}-property-names:${cmake_lang_desc} language property name:_cmake_define_lang_property_names -qS= ${cmake_lang} ${cmake_lang_desc}") + done + + _alternative "${alternatives[@]}" +} + +# --------------------------------- +# _cmake_define_lang_property_names +# --------------------------------- +(( $+functions[_cmake_define_lang_property_names] )) || +_cmake_define_lang_property_names() { + local cmake_lang="$@[-2]" cmake_lang_desc="$@[-1]" + local properties; properties=( + "CMAKE_${cmake_lang}_COMPILER:${cmake_lang_desc} compiler" + "CMAKE_${cmake_lang}_FLAGS:${cmake_lang_desc} compiler flags for all builds" + "CMAKE_${cmake_lang}_FLAGS_DEBUG:${cmake_lang_desc} compiler flags for all Debug build" + "CMAKE_${cmake_lang}_FLAGS_RLEASE:${cmake_lang_desc} compiler flags for all Relase build" + "CMAKE_${cmake_lang}_FLAGS_MINSIZREL:${cmake_lang_desc} compiler flags for all MinSizRel build" + "CMAKE_${cmake_lang}_FLAGS_RELWITHDEBINFO:${cmake_lang_desc} compiler flags for all RelWithDebInfo build" + ) + + _describe -t "${cmake_lang//:/-}-property-names" "${cmake_lang_desc} property name" properties $@[0,-3] && return 0 +} + +# ----------------------------------- +# _cmake_define_common_property_names +# ----------------------------------- +(( $+functions[_cmake_define_common_property_names] )) || +_cmake_define_common_property_names() { + local properties; properties=( + 'CMAKE_BUILD_TYPE:Specifies the build type for make based generators' + 'CMAKE_TOOLCHAIN_FILE:Absolute or relative path to a cmake script which sets up toolchain related variables' + 'CMAKE_COLOR_MAKEFILE:Enables/disables color output when using the Makefile generator' + 'CMAKE_INSTALL_PREFIX:Install directory used by install' + ) + + _describe -t 'common-property-names' 'common property name' properties $@ +} + +# ---------------------------- +# _cmake_define_property_values +# ---------------------------- +(( $+functions[_cmake_define_property_values] )) || +_cmake_define_property_values() { + local ret=1 + setopt localoptions extendedglob + case $@[-1] in + (CMAKE_BUILD_TYPE) _wanted build-types expl 'build type' _cmake_build_types && ret=0;; + (CMAKE_TOOLCHAIN_FILE) _wanted toolchain-files expl 'file' _cmake_toolchain_files && ret=0;; + (CMAKE_COLOR_MAKEFILE) _wanted booleans expl 'boolean' _cmake_booleans && ret=0;; + (CMAKE_INSTALL_PREFIX) _files -/ && ret=0;; + (CMAKE_*_COMPILER) _wanted compilers expl 'compiler' _cmake_compilers && ret=0;; + (CMAKE_*_FLAGS(|_?*)) _message -e compiler-flags 'compiler flags' && ret=0;; + (*) _files && ret=0;; + esac + + return ret +} + +# ------------------ +# _cmake_build_types +# ------------------ +(( $+functions[_cmake_build_types] )) || +_cmake_build_types() { + local build_types; build_types=( + 'Debug' + 'Release' + 'RelWithDebInfo' + 'MinSizeRel' + ) + _values 'build type' ${build_types[@]} +} + +# ----------------- +# _cmake_generators +# ----------------- +(( $+functions[_cmake_generators] )) || +_cmake_generators() { + local generators; generators=( + 'Unix Makefiles' + 'Ninja' + 'CodeBlocks - Ninja' + 'CodeBlocks - Unix Makefiles' + 'Eclipse CDT4 - Ninja' + 'Eclipse CDT4 - Unix Makefiles' + 'KDevelop3' + 'KDevelop3 - Unix Makefiles' + 'Sublime Text 2 - Ninja' + 'Sublime Text 2 - Unix Makefiles' + ) + + _describe -t generators 'generator' generators +} + +# ---------------------- +# _cmake_toolchain_files +# ---------------------- +(( $+functions[_cmake_toolchain_files] )) || +_cmake_toolchain_files() { + _files -g '*\.cmake*' +} + +# --------------- +# _cmake_booleans +# --------------- +(( $+functions[_cmake_booleans] )) || +_cmake_booleans() { + local booleans; booleans=( + 'YES' + 'NO' + ) + _describe -t booleans 'boolean' booleans +} + +# --------------- +# _cmake_compilers +# --------------- +(( $+functions[_cmake_compilers] )) || +_cmake_compilers() { + _command_names -e +} + + +_cmake "$@" + diff --git a/zsh/.zsh/completion/_composer b/zsh/.zsh/completion/_composer new file mode 100644 index 0000000..f30360f --- /dev/null +++ b/zsh/.zsh/completion/_composer @@ -0,0 +1,76 @@ +#compdef composer +# ------------------------------------------------------------------------------ +# Copyright (c) 2011 Github zsh-users - http://github.com/zsh-users +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the zsh-users nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL ZSH-USERS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------ +# Description +# ----------- +# +# Completion script for composer (https://getcomposer.org/). +# +# ------------------------------------------------------------------------------ +# Authors +# ------- +# +# * Daniel Gomes (me@danielcsgomes.com) +# * Valerii Hiora (https://github.com/vhbit) +# * loranger (https://github.com/loranger) +# +# ------------------------------------------------------------------------------ + +local curcontext=$curcontext state line +declare -A opt_args + +_composer_get_command_list () { + composer --no-ansi | sed "1,/Available commands/d" | awk '/ [a-z]+/ { print $1 }' +} + +_composer_get_required_list () { + composer show -s --no-ansi | sed '1,/requires/d' | awk 'NF > 0 && !/^requires \(dev\)/{ print $1 }' +} + + +_composer () { + local curcontext="$curcontext" state line + typeset -A opt_args + + _arguments \ + '1: :->command'\ + '*: :->args' + if [ -f composer.json ]; then + case $state in + command) + compadd `_composer_get_command_list` + ;; + *) + compadd `_composer_get_required_list` + ;; + esac + else + compadd create-project init search selfupdate show + fi +} + +compdef _composer composer diff --git a/zsh/.zsh/completion/_docker b/zsh/.zsh/completion/_docker new file mode 100644 index 0000000..3215814 --- /dev/null +++ b/zsh/.zsh/completion/_docker @@ -0,0 +1,514 @@ +#compdef docker +# +# zsh completion for docker (http://docker.com) +# +# version: 0.3.0 +# github: https://github.com/felixr/docker-zsh-completion +# +# contributors: +# - Felix Riedel +# - Vincent Bernat +# +# license: +# +# Copyright (c) 2013, Felix Riedel +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the <organization> nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +__docker_get_containers() { + local kind expl + declare -a running stopped lines args + + kind=$1 + shift + [[ $kind = (stopped|all) ]] && args=($args -a) + + lines=(${(f)"$(_call_program commands docker ps ${args})"}) + + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( $j < ${#header} - 1 )) { + i=$(( $j + ${${header[$j,-1]}[(i)[^ ]]} - 1)) + j=$(( $i + ${${header[$i,-1]}[(i) ]} - 1)) + k=$(( $j + ${${header[$j,-1]}[(i)[^ ]]} - 2)) + begin[${header[$i,$(($j-1))]}]=$i + end[${header[$i,$(($j-1))]}]=$k + } + lines=(${lines[2,-1]}) + + # Container ID + local line + local s + for line in $lines; do + s="${line[${begin[CONTAINER ID]},${end[CONTAINER ID]}]%% ##}" + s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}" + s="$s, ${${${line[$begin[IMAGE],$end[IMAGE]]}/:/\\:}%% ##}" + if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = Exit* ]]; then + stopped=($stopped $s) + else + running=($running $s) + fi + done + + # Names + local name + local -a names + for line in $lines; do + names=(${(ps:,:)${${line[${begin[NAMES]},-1]}%% *}}) + for name in $names; do + s="${name}:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}" + s="$s, ${${${line[$begin[IMAGE],$end[IMAGE]]}/:/\\:}%% ##}" + if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = Exit* ]]; then + stopped=($stopped $s) + else + running=($running $s) + fi + done + done + + [[ $kind = (running|all) ]] && _describe -t containers-running "running containers" running + [[ $kind = (stopped|all) ]] && _describe -t containers-stopped "stopped containers" stopped +} + +__docker_stoppedcontainers() { + __docker_get_containers stopped "$@" +} + +__docker_runningcontainers() { + __docker_get_containers running "$@" +} + +__docker_containers () { + __docker_get_containers all "$@" +} + +__docker_images () { + local expl + declare -a images + images=(${${${${(f)"$(_call_program commands docker images)"}[2,-1]}/ ##/\\:}%% *}) + images=(${${images%\\:<none>}#<none>} ${${${(f)"$(_call_program commands docker images)"}[2,-1]}/(#b)([^ ]##) ##([^ ]##) ##([^ ]##)*/${match[3]}:${(r:15:: :::)match[2]} in ${match[1]}}) + _describe -t docker-images "images" images +} + +__docker_tags() { + local expl + declare -a tags + tags=(${${${${${(f)"$(_call_program commands docker images)"}#* }## #}%% *}[2,-1]}) + _describe -t docker-tags "tags" tags +} + +__docker_repositories_with_tags() { + if compset -P '*:'; then + __docker_tags + else + __docker_repositories -qS ":" + fi +} + +__docker_search() { + # declare -a dockersearch + local cache_policy + zstyle -s ":completion:${curcontext}:" cache-policy cache_policy + if [[ -z "$cache_policy" ]]; then + zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy + fi + + local searchterm cachename + searchterm="${words[$CURRENT]%/}" + cachename=_docker-search-$searchterm + + local expl + local -a result + if ( [[ ${(P)+cachename} -eq 0 ]] || _cache_invalid ${cachename#_} ) \ + && ! _retrieve_cache ${cachename#_}; then + _message "Searching for ${searchterm}..." + result=(${${${(f)"$(_call_program commands docker search ${searchterm})"}%% *}[2,-1]}) + _store_cache ${cachename#_} result + fi + _wanted dockersearch expl 'available images' compadd -a result +} + +__docker_caching_policy() +{ + oldp=( "$1"(Nmh+1) ) # 1 hour + (( $#oldp )) +} + + +__docker_repositories () { + local expl + declare -a repos + repos=(${${${(f)"$(_call_program commands docker images)"}%% *}[2,-1]}) + _describe -t docker-repos "repositories" repos "$@" +} + +__docker_commands () { + # local -a _docker_subcommands + local cache_policy + + zstyle -s ":completion:${curcontext}:" cache-policy cache_policy + if [[ -z "$cache_policy" ]]; then + zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy + fi + + if ( [[ ${+_docker_subcommands} -eq 0 ]] || _cache_invalid docker_subcommands) \ + && ! _retrieve_cache docker_subcommands; + then + local -a lines + lines=(${(f)"$(_call_program commands docker 2>&1)"}) + _docker_subcommands=(${${${lines[$((${lines[(i)Commands:]} + 1)),${lines[(I) *]}]}## #}/ ##/:}) + _docker_subcommands=($_docker_subcommands 'help:Show help for a command') + _store_cache docker_subcommands _docker_subcommands + fi + _describe -t docker-commands "docker command" _docker_subcommands +} + +__docker_subcommand () { + local -a _command_args + case "$words[1]" in + (attach) + _arguments \ + '--no-stdin[Do not attach stdin]' \ + '--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]' \ + ':containers:__docker_runningcontainers' + ;; + (build) + _arguments \ + {-f,--file=-}'[Dockerfile to use]:Dockerfile:_files' \ + '--force-rm[Always remove intermediate containers]' \ + '--no-cache[Do not use cache when building the image]' \ + '--pull[Attempt to pull a newer version of the image]' \ + {-q,--quiet}'[Suppress verbose build output]' \ + '--rm[Remove intermediate containers after a successful build]' \ + {-t,--tag=-}'[Repository, name and tag to be applied]:repository:__docker_repositories_with_tags' \ + ':path or URL:_directories' + ;; + (commit) + _arguments \ + {-a,--author=-}'[Author]:author: ' \ + {-m,--message=-}'[Commit message]:message: ' \ + {-p,--pause}'[Pause container during commit]' \ + ':container:__docker_containers' \ + ':repository:__docker_repositories_with_tags' + ;; + (cp) + _arguments \ + ':container:->container' \ + ':hostpath:_files' + case $state in + (container) + if compset -P '*:'; then + _files + else + __docker_containers -qS ":" + fi + ;; + esac + ;; + (diff|export) + _arguments '*:containers:__docker_containers' + ;; + (events) + _arguments \ + '*'{-f,--filter=-}'[Filter values]:filter: ' \ + '--since=-[Events created since this timestamp]:timestamp: ' \ + '--until=-[Events created until this timestamp]:timestamp: ' + ;; + (exec) + local state ret + _arguments \ + {-d,--detach}'[Detached mode: leave the container running in the background]' \ + {-i,--interactive}'[Keep stdin open even if not attached]' \ + {-t,--tty}'[Allocate a pseudo-tty]' \ + ':containers:__docker_runningcontainers' \ + '*::command:->anycommand' && ret=0 + + case $state in + (anycommand) + shift 1 words + (( CURRENT-- )) + _normal + ;; + esac + + return ret + ;; + (history) + _arguments \ + '--no-trunc[Do not truncate output]' \ + {-q,--quiet}'[Only show numeric IDs]' \ + '*:images:__docker_images' + ;; + (images) + _arguments \ + {-a,--all}'[Show all images]' \ + '*'{-f,--filter=-}'[Filter values]:filter: ' \ + '--no-trunc[Do not truncate output]' \ + {-q,--quiet}'[Only show numeric IDs]' \ + ':repository:__docker_repositories' + ;; + (inspect) + _arguments \ + {-f,--format=-}'[Format the output using the given go template]:template: ' \ + '*:containers:__docker_containers' + ;; + (import) + _arguments \ + ':URL:(- http:// file://)' \ + ':repository:__docker_repositories_with_tags' + ;; + (info) + ;; + (import) + _arguments \ + ':URL:(- http:// file://)' \ + ':repository:__docker_repositories_with_tags' + ;; + (insert) + _arguments '1:containers:__docker_containers' \ + '2:URL:(http:// file://)' \ + '3:file:_files' + ;; + (kill) + _arguments \ + {-s,--signal=-}'[Signal to send]:signal:_signals' \ + '*:containers:__docker_runningcontainers' + ;; + (load) + _arguments \ + {-i,--input=-}'[Read from tar archive file]:archive file:_files -g "*.((tar|TAR)(.gz|.GZ|.Z|.bz2|.lzma|.xz|)|(tbz|tgz|txz))(-.)"' + ;; + (login) + _arguments \ + {-e,--email=-}'[Email]:email: ' \ + {-p,--password=-}'[Password]:password: ' \ + {-u,--user=-}'[Username]:username: ' \ + ':server: ' + ;; + (logout) + _arguments \ + ':server: ' + ;; + (logs) + _arguments \ + {-f,--follow}'[Follow log output]' \ + {-t,--timestamps}'[Show timestamps]' \ + '--tail=-[Output the last K lines]:lines:(1 10 20 50 all)' \ + '*:containers:__docker_containers' + ;; + (port) + _arguments \ + '1:containers:__docker_runningcontainers' \ + '2:port:_ports' + ;; + (pause|unpause) + _arguments \ + '1:containers:__docker_runningcontainers' + ;; + (start) + _arguments \ + {-a,--attach}'[Attach container'"'"'s stdout/stderr and forward all signals]' \ + {-i,--interactive}'[Attach container'"'"'s stding]' \ + '*:containers:__docker_stoppedcontainers' + ;; + (stats) + _arguments \ + '*:containers:__docker_runningcontainers' + ;; + (rm) + _arguments \ + {-f,--force}'[Force removal]' \ + {-l,--link}'[Remove the specified link and not the underlying container]' \ + {-v,--volumes}'[Remove the volumes associated to the container]' \ + '*:containers:__docker_stoppedcontainers' + ;; + (rmi) + _arguments \ + {-f,--force}'[Force removal]' \ + '--no-prune[Do not delete untagged parents]' \ + '*:images:__docker_images' + ;; + (restart|stop) + _arguments \ + {-t,--time=-}'[Number of seconds to try to stop for before killing the container]:seconds to before killing:(1 5 10 30 60)' \ + '*:containers:__docker_runningcontainers' + ;; + (top) + _arguments \ + '1:containers:__docker_runningcontainers' \ + '(-)*:: :->ps-arguments' + case $state in + (ps-arguments) + _ps + ;; + esac + + ;; + (ps) + _arguments \ + {-a,--all}'[Show all containers]' \ + '--before=-[Show only container created before...]:containers:__docker_containers' \ + '*'{-f,--filter=-}'[Filter values]:filter: ' \ + {-l,--latest}'[Show only the latest created container]' \ + '-n[Show n last created containers, include non-running one]:n:(1 5 10 25 50)' \ + '--no-trunc[Do not truncate output]' \ + {-q,--quiet}'[Only show numeric IDs]' \ + {-s,--size}'[Display total file sizes]' \ + '--since=-[Show only containers created since...]:containers:__docker_containers' + ;; + (tag) + _arguments \ + {-f,--force}'[force]'\ + ':image:__docker_images'\ + ':repository:__docker_repositories_with_tags' + ;; + (create|run) + _arguments \ + {-a,--attach}'[Attach to stdin, stdout or stderr]' \ + '*--add-host=-[Add a custom host-to-IP mapping]:host\:ip mapping: ' \ + {-c,--cpu-shares=-}'[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)' \ + '*--cap-add=-[Add Linux capabilities]:capability: ' \ + '*--cap-drop=-[Drop Linux capabilities]:capability: ' \ + '--cidfile=-[Write the container ID to the file]:CID file:_files' \ + '--cpuset=-[CPUs in which to allow execution]:CPU set: ' \ + {-d,--detach}'[Detached mode: leave the container running in the background]' \ + '*--device=-[Add a host device to the container]:device:_files' \ + '*--dns=-[Set custom dns servers]:dns server: ' \ + '*--dns-search=-[Set custom DNS search domains]:dns domains: ' \ + '*'{-e,--environment=-}'[Set environment variables]:environment variable: ' \ + '--entrypoint=-[Overwrite the default entrypoint of the image]:entry point: ' \ + '*--env-file=-[Read environment variables from a file]:environment file:_files' \ + '*--expose=-[Expose a port from the container without publishing it]: ' \ + {-h,--hostname=-}'[Container host name]:hostname:_hosts' \ + {-i,--interactive}'[Keep stdin open even if not attached]' \ + '*--link=-[Add link to another container]:link:->link' \ + '*--lxc-conf=-[Add custom lxc options]:lxc options: ' \ + '-m[Memory limit (in bytes)]:limit: ' \ + '--name=-[Container name]:name: ' \ + '--net=-[Network mode]:network mode:(bridge none container host)' \ + {-P,--publish-all}'[Publish all exposed ports]' \ + '*'{-p,--publish=-}'[Expose a container'"'"'s port to the host]:port:_ports' \ + '--privileged[Give extended privileges to this container]' \ + '--restart=-[Restart policy]:restart policy:(no on-failure always)' \ + '--rm[Remove intermediate containers when it exits]' \ + '*--security-opt=-[Security options]:security option: ' \ + '--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]' \ + {-t,--tty}'[Allocate a pseudo-tty]' \ + {-u,--user=-}'[Username or UID]:user:_users' \ + '*-v[Bind mount a volume]:volume: '\ + '*--volumes-from=-[Mount volumes from the specified container]:volume: ' \ + {-w,--workdir=-}'[Working directory inside the container]:directory:_directories' \ + '(-):images:__docker_images' \ + '(-):command: _command_names -e' \ + '*::arguments: _normal' + + case $state in + (link) + if compset -P '*:'; then + _wanted alias expl 'Alias' compadd -E "" + else + __docker_runningcontainers -qS ":" + fi + ;; + esac + + ;; + (pull) + _arguments \ + {-a,--all-tags}'[Download all tagged images]' \ + ':name:__docker_search' + ;; + (push) + _arguments ':images:__docker_images' + ;; + (rename) + _arguments \ + ':old name:__docker_containers' \ + ':new name: ' + ;; + (save) + _arguments \ + {-o,--output=-}'[Write to file]:file:_files' \ + '*:images:__docker_images' + ;; + (search) + _arguments \ + '--automated[Only show automated builds]' \ + '--no-trunc[Do not truncate output]' \ + {-s,--stars=-}'[Only display with at least X stars]:stars:(0 10 100 1000)' \ + ':term: ' + ;; + (wait) + _arguments '*:containers:__docker_runningcontainers' + ;; + (help) + _arguments ':subcommand:__docker_commands' + ;; + (*) + _message 'Unknown sub command' + esac + +} + +_docker () { + # Support for subservices, which allows for `compdef _docker docker-shell=_docker_containers`. + # Based on /usr/share/zsh/functions/Completion/Unix/_git without support for `ret`. + if [[ $service != docker ]]; then + _call_function - _$service + return + fi + + local curcontext="$curcontext" state line + typeset -A opt_args + + _arguments -C \ + '-H[tcp://host:port to bind/connect to]:socket: ' \ + '(-): :->command' \ + '(-)*:: :->option-or-argument' + + if (( CURRENT == 1 )); then + + fi + case $state in + (command) + __docker_commands + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-$words[1]: + __docker_subcommand + ;; + esac +} + +_docker "$@" + +# Local Variables: +# mode: Shell-Script +# sh-indentation: 4 +# indent-tabs-mode: nil +# sh-basic-offset: 4 +# End: +# vim: ft=zsh sw=4 ts=4 et diff --git a/zsh/.zsh/completion/_hub b/zsh/.zsh/completion/_hub new file mode 100644 index 0000000..df09ace --- /dev/null +++ b/zsh/.zsh/completion/_hub @@ -0,0 +1,160 @@ +#compdef hub + +# Zsh will source this file when attempting to autoload the "_hub" function, +# typically on the first attempt to complete the hub command. We define two new +# setup helper routines (one for the zsh-distributed version, one for the +# git-distributed, bash-based version). Then we redefine the "_hub" function to +# call "_git" after some other interception. +# +# This is pretty fragile, if you think about it. Any number of implementation +# changes in the "_git" scripts could cause problems down the road. It would be +# better if the stock git completions were just a bit more permissive about how +# it allowed third-party commands to be added. + +(( $+functions[__hub_setup_zsh_fns] )) || +__hub_setup_zsh_fns () { + (( $+functions[_git-alias] )) || + _git-alias () { + _arguments \ + '-s[output shell script suitable for eval]' \ + '1::shell:(zsh bash csh)' + } + + (( $+functions[_git-browse] )) || + _git-browse () { + _arguments \ + '-u[output the URL]' \ + '2::subpage:(wiki commits issues)' + } + + (( $+functions[_git-compare] )) || + _git-compare () { + _arguments \ + '-u[output the URL]' \ + ':[start...]end range:' + } + + (( $+functions[_git-create] )) || + _git-create () { + _arguments \ + '::name (REPOSITORY or ORGANIZATION/REPOSITORY):' \ + '-p[make repository private]' \ + '-d[description]:description' \ + '-h[home page]:repository home page URL:_urls' + } + + (( $+functions[_git-fork] )) || + _git-fork () { + _arguments \ + '--no-remote[do not add a remote for the new fork]' + } + + (( $+functions[_git-pull-request] )) || + _git-pull-request () { + _arguments \ + '-f[force (skip check for local commits)]' \ + '-b[base]:base ("branch", "owner\:branch", "owner/repo\:branch"):' \ + '-h[head]:head ("branch", "owner\:branch", "owner/repo\:branch"):' \ + - set1 \ + '-m[message]' \ + '-F[file]' \ + - set2 \ + '-i[issue]:issue number:' \ + - set3 \ + '::issue-url:_urls' + } + + # stash the "real" command for later + functions[_hub_orig_git_commands]=$functions[_git_commands] + + # Replace it with our own wrapper. + declare -f _git_commands >& /dev/null && unfunction _git_commands + _git_commands () { + local ret=1 + # call the original routine + _call_function ret _hub_orig_git_commands + + # Effectively "append" our hub commands to the behavior of the original + # _git_commands function. Using this wrapper function approach ensures + # that we only offer the user the hub subcommands when the user is + # actually trying to complete subcommands. + hub_commands=( + alias:'show shell instructions for wrapping git' + pull-request:'open a pull request on GitHub' + fork:'fork origin repo on GitHub' + create:'create new repo on GitHub for the current project' + browse:'browse the project on GitHub' + compare:'open GitHub compare view' + ci-status:'lookup commit in GitHub Status API' + ) + _describe -t hub-commands 'hub command' hub_commands && ret=0 + + return ret + } +} + +(( $+functions[__hub_setup_bash_fns] )) || +__hub_setup_bash_fns () { + # TODO more bash-style fns needed here to complete subcommand args. They take + # the form "_git_CMD" where "CMD" is something like "pull-request". + + # Duplicate and rename the 'list_all_commands' function + eval "$(declare -f __git_list_all_commands | \ + sed 's/__git_list_all_commands/__git_list_all_commands_without_hub/')" + + # Wrap the 'list_all_commands' function with extra hub commands + __git_list_all_commands() { + cat <<-EOF +alias +pull-request +fork +create +browse +compare +ci-status +EOF + __git_list_all_commands_without_hub + } + + # Ensure cached commands are cleared + __git_all_commands="" +} + +# redefine _hub to a much smaller function in the steady state +_hub () { + # only attempt to intercept the normal "_git" helper functions once + (( $+__hub_func_replacement_done )) || + () { + # At this stage in the shell's execution the "_git" function has not yet + # been autoloaded, so the "_git_commands" or "__git_list_all_commands" + # functions will not be defined. Call it now (with a bogus no-op service + # to prevent premature completion) so that we can wrap them. + if declare -f _git >& /dev/null ; then + _hub_noop () { __hub_zsh_provided=1 } # zsh-provided will call this one + __hub_noop_main () { __hub_git_provided=1 } # git-provided will call this one + local service=hub_noop + _git + unfunction _hub_noop + unfunction __hub_noop_main + service=git + fi + + if (( $__hub_zsh_provided )) ; then + __hub_setup_zsh_fns + elif (( $__hub_git_provided )) ; then + __hub_setup_bash_fns + fi + + __hub_func_replacement_done=1 + } + + # Now perform the actual completion, allowing the "_git" function to call our + # replacement "_git_commands" function as needed. Both versions expect + # service=git or they will call nonexistent routines or end up in an infinite + # loop. + service=git + declare -f _git >& /dev/null && _git +} + +# make sure we actually attempt to complete on the first "tab" from the user +_hub diff --git a/zsh/.zsh/completion/_node b/zsh/.zsh/completion/_node new file mode 100644 index 0000000..f9ef3c7 --- /dev/null +++ b/zsh/.zsh/completion/_node @@ -0,0 +1,66 @@ +#compdef node +# ------------------------------------------------------------------------------ +# Copyright (c) 2011 Github zsh-users - http://github.com/zsh-users +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the zsh-users nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL ZSH-USERS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------ +# Description +# ----------- +# +# Completion script for Node.js v0.8.4 (http://nodejs.org) +# +# ------------------------------------------------------------------------------ +# Authors +# ------- +# +# * Mario Fernandez (https://github.com/sirech) +# * Nicholas Penree (https://github.com/drudge) +# +# ------------------------------------------------------------------------------ + +local curcontext="$curcontext" state line ret=1 +typeset -A opt_args + +_arguments -C \ + '(- 1 *)--help[print options help]' \ + '(- 1 *)'{-v,--version}'[print node version]' \ + '(--no-deprecation)--no-deprecation[silence deprecation warnings]' \ + '(--trace-deprecation)--trace-deprecation[show stack traces on deprecations]' \ + '(- 1 *)--v8-options[print v8 command line options]' \ + '(--max-stack-size)--max-stack-size=[set max v8 stack size (bytes)]' \ + '(-e --eval)'{-e,--eval}'[evaluate script]:Inline Script' \ + '(-i --interactive)'{-i,--interactive}'[always enter the REPL even if stdin does not appear to be a terminal]' \ + '(-p --print)'{-p,--print}'[print result of --eval]' \ + '(--vars)--vars[print various compiled-in variables]' \ + '*:JS Script:_files -g "*.js"' && ret=0 + +return ret + +# Local Variables: +# mode: Shell-Script +# sh-indentation: 2 +# indent-tabs-mode: nil +# sh-basic-offset: 2 +# End: +# vim: ft=zsh sw=2 ts=2 et diff --git a/zsh/.zsh/completion/_nvm b/zsh/.zsh/completion/_nvm new file mode 100644 index 0000000..2f6acc5 --- /dev/null +++ b/zsh/.zsh/completion/_nvm @@ -0,0 +1,85 @@ +#compdef nvm +# ------------------------------------------------------------------------------ +# Description +# ----------- +# +# Completion script for nvm (https://github.com/creationix/nvm). +# +# ------------------------------------------------------------------------------ +# Authors +# ------- +# +# * Changwoo Park (https://github.com/pismute) +# +# ------------------------------------------------------------------------------ + +local curcontext="$curcontext" state line ret=1 + +local -a _1st_arguments +_1st_arguments=( + 'help:Show this message' + 'install:Download and install a <version>' + 'uninstall:Uninstall a <version>' + 'use:Modify PATH to use <version>' + 'run:Run <version> with <args> as arguments' + 'ls:List installed [versions]' + 'ls-remote:List remote versions available for install' + 'deactivate:Undo effects of NVM on current shell' + 'alias:Set an alias named <name> pointing to <version>. Show all aliases beginning with [<pattern>].' + 'unalias:Deletes the alias named <name>' + 'copy-packages:Install global NPM packages contained in <version> to current version' + 'clear-cache:Clear cache' + 'version:Show current node version' +) + +_arguments -C \ + '1: :->cmds' \ + '*: :->args' && ret=0 + +__nvm_aliases(){ + local aliases + aliases="" + if [ -d $NVM_DIR/alias ]; then + aliases="`cd $NVM_DIR/alias && ls`" + fi + echo "${aliases}" +} + +__nvm_versions(){ + echo "$(nvm_ls) $(__nvm_aliases)" +} + +case $state in + cmds) + _describe -t commands 'nvm command' _1st_arguments && ret=0 + ;; + + args) + case $words[2] in + (use|run|ls|list|install|uninstall|copy-packages) + + _values 'version' $(__nvm_versions) && ret=0 + ;; + + (alias|unalias) + + _values 'aliases' $(__nvm_aliases) && ret=0 + ;; + + *) + (( ret )) && _message 'no more arguments' + ;; + + esac + ;; +esac + +return ret + +# Local Variables: +# mode: Shell-Script +# sh-indentation: 2 +# indent-tabs-mode: nil +# sh-basic-offset: 2 +# End: +# vim: ft=zsh sw=2 ts=2 et |