96e5346efb4082c20c6d5cc4cd5512208a14202f

Author
Andrew Stuart <andrew.stuart2@gmail.com>
Committer
Andrew Stuart <andrew.stuart2@gmail.com>
Date

Message

Merge branch 'master' of gh:robbyrussell/oh-my-zsh

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/docker-compose/README.md b/plugins/docker-compose/README.md
  2index 77b98f30df1ff85b1bebf4ed213548408f26fddb..567b821487af846fa41948fea666f7de6280954f 100644
  3--- a/plugins/docker-compose/README.md
  4+++ b/plugins/docker-compose/README.md
  5@@ -1 +1,5 @@
  6 # Docker-compose plugin for oh my zsh
  7+
  8+A copy of the completion script from the [docker-compose](1) git repo.
  9+
 10+[1]:[https://github.com/docker/compose/blob/master/contrib/completion/zsh/_docker-compose]
 11diff --git a/plugins/docker-compose/_docker-compose b/plugins/docker-compose/_docker-compose
 12new file mode 100644
 13index 0000000000000000000000000000000000000000..19c06675ad5057dd09b3398e476744ac8fdd8b10
 14--- /dev/null
 15+++ b/plugins/docker-compose/_docker-compose
 16@@ -0,0 +1,308 @@
 17+#compdef docker-compose
 18+
 19+# Description
 20+# -----------
 21+#  zsh completion for docker-compose
 22+#  https://github.com/sdurrheimer/docker-compose-zsh-completion
 23+# -------------------------------------------------------------------------
 24+# Version
 25+# -------
 26+#  0.1.0
 27+# -------------------------------------------------------------------------
 28+# Authors
 29+# -------
 30+#  * Steve Durrheimer <s.durrheimer@gmail.com>
 31+# -------------------------------------------------------------------------
 32+# Inspiration
 33+# -----------
 34+#  * @albers docker-compose bash completion script
 35+#  * @felixr docker zsh completion script : https://github.com/felixr/docker-zsh-completion
 36+# -------------------------------------------------------------------------
 37+
 38+# For compatibility reasons, Compose and therefore its completion supports several
 39+# stack compositon files as listed here, in descending priority.
 40+# Support for these filenames might be dropped in some future version.
 41+__docker-compose_compose_file() {
 42+    local file
 43+    for file in docker-compose.y{,a}ml fig.y{,a}ml ; do
 44+        [ -e $file ] && {
 45+            echo $file
 46+            return
 47+        }
 48+    done
 49+    echo docker-compose.yml
 50+}
 51+
 52+# Extracts all service names from docker-compose.yml.
 53+___docker-compose_all_services_in_compose_file() {
 54+    local already_selected
 55+    local -a services
 56+    already_selected=$(echo ${words[@]} | tr " " "|")
 57+    awk -F: '/^[a-zA-Z0-9]/{print $1}' "${compose_file:-$(__docker-compose_compose_file)}" 2>/dev/null | grep -Ev "$already_selected"
 58+}
 59+
 60+# All services, even those without an existing container
 61+__docker-compose_services_all() {
 62+    services=$(___docker-compose_all_services_in_compose_file)
 63+    _alternative "args:services:($services)"
 64+}
 65+
 66+# All services that have an entry with the given key in their docker-compose.yml section
 67+___docker-compose_services_with_key() {
 68+    local already_selected
 69+    local -a buildable
 70+    already_selected=$(echo ${words[@]} | tr " " "|")
 71+    # flatten sections to one line, then filter lines containing the key and return section name.
 72+    awk '/^[a-zA-Z0-9]/{printf "\n"};{printf $0;next;}' "${compose_file:-$(__docker-compose_compose_file)}" 2>/dev/null | awk -F: -v key=": +$1:" '$0 ~ key {print $1}' 2>/dev/null | grep -Ev "$already_selected"
 73+}
 74+
 75+# All services that are defined by a Dockerfile reference
 76+__docker-compose_services_from_build() {
 77+    buildable=$(___docker-compose_services_with_key build)
 78+    _alternative "args:buildable services:($buildable)"
 79+}
 80+
 81+# All services that are defined by an image
 82+__docker-compose_services_from_image() {
 83+    pullable=$(___docker-compose_services_with_key image)
 84+    _alternative "args:pullable services:($pullable)"
 85+}
 86+
 87+__docker-compose_get_services() {
 88+    local kind expl
 89+    declare -a running stopped lines args services
 90+
 91+    docker_status=$(docker ps > /dev/null 2>&1)
 92+    if [ $? -ne 0 ]; then
 93+        _message "Error! Docker is not running."
 94+        return 1
 95+    fi
 96+
 97+    kind=$1
 98+    shift
 99+    [[ $kind = (stopped|all) ]] && args=($args -a)
100+
101+    lines=(${(f)"$(_call_program commands docker ps ${args})"})
102+    services=(${(f)"$(_call_program commands docker-compose 2>/dev/null ${compose_file:+-f $compose_file} ${compose_project:+-p $compose_project} ps -q)"})
103+
104+    # Parse header line to find columns
105+    local i=1 j=1 k header=${lines[1]}
106+    declare -A begin end
107+    while (( $j < ${#header} - 1 )) {
108+        i=$(( $j + ${${header[$j,-1]}[(i)[^ ]]} - 1))
109+        j=$(( $i + ${${header[$i,-1]}[(i)  ]} - 1))
110+        k=$(( $j + ${${header[$j,-1]}[(i)[^ ]]} - 2))
111+        begin[${header[$i,$(($j-1))]}]=$i
112+        end[${header[$i,$(($j-1))]}]=$k
113+    }
114+    lines=(${lines[2,-1]})
115+
116diff --git a/plugins/docker-compose/docker-compose.plugin.zsh b/plugins/docker-compose/docker-compose.plugin.zsh
117deleted file mode 100644
118index 08500408d7a309a116bd8064c829f8fbaea59722..0000000000000000000000000000000000000000
119--- a/plugins/docker-compose/docker-compose.plugin.zsh
120+++ /dev/null
121@@ -1,14 +0,0 @@
122-# Authors:
123-# https://github.com/tristola
124-#
125-# Docker-compose related zsh aliases
126-
127-# Aliases ###################################################################
128-
129-alias dcup='docker-compose up'
130-alias dcb='docker-compose build'
131-alias dcrm='docker-compose rm'
132-alias dcps='docker-compose ps'
133-alias dcstop='docker-compose stop'
134-alias dcrestart='docker-compose restart'
135-
136diff --git a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
137index f5f37ff6f573a2f8303ac7498d9b96d46a2b6b80..c40ca86ac8254a5eaa673eb13a58d70c7dc19e75 100644
138--- a/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
139+++ b/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
140@@ -14,32 +14,38 @@ elif [[ -f "/etc/bash_completion.d/virtualenvwrapper" ]]; then
141     source "/etc/bash_completion.d/virtualenvwrapper"
142   }
143 else
144-  print "zsh virtualenvwrapper plugin: Cannot find ${virtualenvwrapper}.\n"\
145+  print "[oh-my-zsh] virtualenvwrapper plugin: Cannot find ${virtualenvwrapper}.\n"\
146         "Please install with \`pip install virtualenvwrapper\`" >&2
147   return
148 fi
149 if ! type workon &>/dev/null; then
150-  print "zsh virtualenvwrapper plugin: shell function 'workon' not defined.\n"\
151+  print "[oh-my-zsh] virtualenvwrapper plugin: shell function 'workon' not defined.\n"\
152         "Please check ${virtualenvwrapper}" >&2
153   return
154 fi
155 
156 if [[ "$WORKON_HOME" == "" ]]; then
157-  print "\$WORKON_HOME is not defined so ZSH plugin virtualenvwrapper will not work" >&2
158+  print "[oh-my-zsh] \$WORKON_HOME is not defined so plugin virtualenvwrapper will not work" >&2
159   return
160 fi
161 
162 if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then
163-  # Automatically activate Git projects' virtual environments based on the
164+  # Automatically activate Git projects or other customized virtualenvwrapper projects based on the
165   # directory name of the project. Virtual environment name can be overridden
166-  # by placing a .venv file in the project root with a virtualenv name in it
167+  # by placing a .venv file in the project root with a virtualenv name in it.
168   function workon_cwd {
169-    if [ ! $WORKON_CWD ]; then
170-      WORKON_CWD=1
171+    if [[ -z "$WORKON_CWD" ]]; then
172+      local WORKON_CWD=1
173       # Check if this is a Git repo
174+      local GIT_REPO_ROOT=""
175+      local GIT_TOPLEVEL=$(git rev-parse --show-toplevel 2> /dev/null)
176+      if [[ $? == 0 ]]; then
177+        GIT_REPO_ROOT="$GIT_TOPLEVEL"
178+      fi
179       # Get absolute path, resolving symlinks
180-      PROJECT_ROOT="${PWD:A}"
181-      while [[ "$PROJECT_ROOT" != "/" && ! -e "$PROJECT_ROOT/.venv" ]]; do
182+      local PROJECT_ROOT="${PWD:A}"
183+      while [[ "$PROJECT_ROOT" != "/" && ! -e "$PROJECT_ROOT/.venv" \
184+               && ! -d "$PROJECT_ROOT/.git"  && "$PROJECT_ROOT" != "$GIT_REPO_ROOT" ]]; do
185         PROJECT_ROOT="${PROJECT_ROOT:h}"
186       done
187       if [[ "$PROJECT_ROOT" == "/" ]]; then
188@@ -47,7 +53,7 @@ if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then
189       fi
190       # Check for virtualenv name override
191       if [[ -f "$PROJECT_ROOT/.venv" ]]; then
192-        ENV_NAME=`cat "$PROJECT_ROOT/.venv"`
193+        ENV_NAME=`cat "$PROJECT_ROOT/.venv"`        
194       elif [[ -f "$PROJECT_ROOT/.venv/bin/activate" ]];then
195         ENV_NAME="$PROJECT_ROOT/.venv"
196       elif [[ "$PROJECT_ROOT" != "." ]]; then
197@@ -69,8 +75,6 @@ if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then
198         # Note: this only happens if the virtualenv was activated automatically
199         deactivate && unset CD_VIRTUAL_ENV
200       fi
201-      unset PROJECT_ROOT
202-      unset WORKON_CWD
203     fi
204   }
205