Merge pull request #102 from jpschewe/master

Found a bug in the tmux completion
diff --git a/completion/available/fabric-completion.bash b/completion/available/fabric-completion.bash
new file mode 100644
index 0000000..a4aa90f
--- /dev/null
+++ b/completion/available/fabric-completion.bash
@@ -0,0 +1,133 @@
+#!/bin/bash
+#
+# Bash completion support for Fabric (http://fabfile.org/)
+#
+#
+# Copyright (C) 2011 by Konstantin Bakulin
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+# Thanks to:
+# - Adam Vandenberg,
+#   https://github.com/adamv/dotfiles/blob/master/completion_scripts/fab_completion.bash
+#
+# - Enrico Batista da Luz,
+#   https://github.com/ricobl/dotfiles/blob/master/bin/fab_bash_completion
+#
+
+
+# Use cache files for fab tasks or not.
+# If set to "false" command "fab --shortlist" will be executed every time.
+export FAB_COMPLETION_CACHE_TASKS=true
+
+# File name where tasks cache will be stored (in current dir).
+export FAB_COMPLETION_CACHED_TASKS_FILENAME=".fab_tasks~"
+
+
+# Set command to get time of last file modification as seconds since Epoch
+case `uname` in
+    Darwin|FreeBSD)
+        __FAB_COMPLETION_MTIME_COMMAND="stat -f '%m'"
+        ;;
+    *)
+        __FAB_COMPLETION_MTIME_COMMAND="stat -c '%Y'"
+        ;;
+esac
+
+
+#
+# Get time of last fab cache file modification as seconds since Epoch
+#
+function __fab_chache_mtime() {
+    ${__FAB_COMPLETION_MTIME_COMMAND} \
+        $FAB_COMPLETION_CACHED_TASKS_FILENAME | xargs -n 1 expr
+}
+
+
+#
+# Get time of last fabfile file/module modification as seconds since Epoch
+#
+function __fab_fabfile_mtime() {
+    local f="fabfile"
+    if [[ -e "$f.py" ]]; then
+        ${__FAB_COMPLETION_MTIME_COMMAND} "$f.py" | xargs -n 1 expr
+    else
+        # Suppose that it's a fabfile dir
+        find $f/*.py -exec ${__FAB_COMPLETION_MTIME_COMMAND} {} + \
+            | xargs -n 1 expr | sort -n -r | head -1
+    fi
+}
+
+
+#
+# Completion for "fab" command
+#
+function __fab_completion() {
+    # Return if "fab" command doesn't exists
+    [[ -e `which fab 2> /dev/null` ]] || return 0
+
+    # Variables to hold the current word and possible matches
+    local cur="${COMP_WORDS[COMP_CWORD]}"
+    local opts=()
+
+    # Generate possible matches and store them in variable "opts"
+    case "${cur}" in
+        -*)
+            if [[ -z "${__FAB_COMPLETION_LONG_OPT}" ]]; then
+                export __FAB_COMPLETION_LONG_OPT=$(
+                    fab --help | egrep -o "\-\-[A-Za-z_\-]+\=?" | sort -u)
+            fi
+            opts="${__FAB_COMPLETION_LONG_OPT}"
+            ;;
+
+        # Completion for short options is not nessary.
+        # It's left here just for history.
+        # -*)
+        #     if [[ -z "${__FAB_COMPLETION_SHORT_OPT}" ]]; then
+        #         export __FAB_COMPLETION_SHORT_OPT=$(
+        #             fab --help | egrep -o "^ +\-[A-Za-z_\]" | sort -u)
+        #     fi
+        #     opts="${__FAB_COMPLETION_SHORT_OPT}"
+        #     ;;
+
+        *)
+            # If "fabfile.py" or "fabfile" dir with "__init__.py" file exists
+            local f="fabfile"
+            if [[ -e "$f.py" || (-d "$f" && -e "$f/__init__.py") ]]; then
+                # Build a list of the available tasks
+                if $FAB_COMPLETION_CACHE_TASKS; then
+                    # If use cache
+                    if [[ ! -s ${FAB_COMPLETION_CACHED_TASKS_FILENAME} ||
+                          $(__fab_fabfile_mtime) -gt $(__fab_chache_mtime) ]]; then
+                        fab --shortlist > ${FAB_COMPLETION_CACHED_TASKS_FILENAME} \
+                            2> /dev/null
+                    fi
+                    opts=$(cat ${FAB_COMPLETION_CACHED_TASKS_FILENAME})
+                else
+                    # Without cache
+                    opts=$(fab --shortlist 2> /dev/null)
+                fi
+            fi
+            ;;
+    esac
+
+    # Set possible completions
+    COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
+}
+complete -o default -o nospace -F __fab_completion fab
diff --git a/completion/available/tmux.completion.bash b/completion/available/tmux.completion.bash
index 87008a3..e8ee5e7 100644
--- a/completion/available/tmux.completion.bash
+++ b/completion/available/tmux.completion.bash
@@ -1,3 +1,5 @@
+#!/bin/bash
+
 # tmux completion
 # See: http://www.debian-administration.org/articles/317 for how to write more.
 # Usage: Put "source bash_completion_tmux.sh" into your .bashrc
@@ -124,7 +126,7 @@
                 -t) _tmux_complete_session "${cur}" ;;
                 *) options="-t -d" ;;
             esac ;;
-            new-sesison|new)
+            new-session|new)
             case "$prev" in
                 -t) _tmux_complete_session "${cur}" ;;
                 -[n|d|s]) options="-d -n -s -t --" ;;
diff --git a/plugins/available/z_autoenv.plugins.bash b/plugins/available/z_autoenv.plugins.bash
new file mode 100644
index 0000000..04efa85
--- /dev/null
+++ b/plugins/available/z_autoenv.plugins.bash
@@ -0,0 +1,43 @@
+#!/usr/bin/env bash
+if [[ -n "${ZSH_VERSION}" ]]
+then __array_offset=0
+else __array_offset=1
+fi
+
+autoenv_init()
+{
+  typeset target home _file
+  typeset -a _files
+  target=$1
+  home="$(dirname $HOME)"
+
+  _files=( $(
+    while [[ "$PWD" != "/" && "$PWD" != "$home" ]]
+    do
+      _file="$PWD/.env"
+      if [[ -e "${_file}" ]]
+      then echo "${_file}"
+      fi
+      builtin cd ..
+    done
+  ) )
+
+  _file=${#_files[@]}
+  while (( _file > 0 ))
+  do
+    source "${_files[_file-__array_offset]}"
+    : $(( _file -= 1 ))
+  done
+}
+
+cd()
+{
+  if builtin cd "$@"
+  then
+    autoenv_init
+    return 0
+  else
+    echo "else?"
+    return $?
+  fi
+}
diff --git a/themes/colors.theme.bash b/themes/colors.theme.bash
index 9d756ee..a04c8e4 100644
--- a/themes/colors.theme.bash
+++ b/themes/colors.theme.bash
@@ -182,15 +182,15 @@
 }
 
 
-black="$(color black)"
-red="$(color red)"
-green="$(color green)"
-yellow="$(color yellow)"
-blue="$(color blue)"
-purple="$(color magenta)"
-cyan="$(color cyan)"
-white="$(color white bold)"
-orange="$(color red fg bright)"
+black="$(color reset black)"
+red="$(color reset red)"
+green="$(color reset green)"
+yellow="$(color reset yellow)"
+blue="$(color reset blue)"
+purple="$(color reset magenta)"
+cyan="$(color reset cyan)"
+white="$(color reset white bold)"
+orange="$(color reset red fg bright)"
 
 bold_black="$(color black bold)"
 bold_red="$(color red bold)"
@@ -226,15 +226,15 @@
 reset_color="$(__make_ansi '' 39)"
 
 # These colors are meant to be used with `echo -e`
-echo_black="$(echo_color black)"
-echo_red="$(echo_color red)"
-echo_green="$(echo_color green)"
-echo_yellow="$(echo_color yellow)"
-echo_blue="$(echo_color blue)"
-echo_purple="$(echo_color magenta)"
-echo_cyan="$(echo_color cyan)"
-echo_white="$(echo_color white bold)"
-echo_orange="$(echo_color red fg bright)"
+echo_black="$(echo_color reset black)"
+echo_red="$(echo_color reset red)"
+echo_green="$(echo_color reset green)"
+echo_yellow="$(echo_color reset yellow)"
+echo_blue="$(echo_color reset blue)"
+echo_purple="$(echo_color reset magenta)"
+echo_cyan="$(echo_color reset cyan)"
+echo_white="$(echo_color reset white bold)"
+echo_orange="$(echo_color reset red fg bright)"
 
 echo_bold_black="$(echo_color black bold)"
 echo_bold_red="$(echo_color red bold)"