Merge remote-tracking branch 'edubxb/master'
diff --git a/themes/base.theme.bash b/themes/base.theme.bash
index 001ca65..96c7cf0 100644
--- a/themes/base.theme.bash
+++ b/themes/base.theme.bash
@@ -70,18 +70,28 @@
 }
 
 function git_prompt_vars {
-  if [[ -n $(git status -s 2> /dev/null |grep -v ^# |grep -v "working directory clean") ]]; then
+  SCM_GIT_AHEAD=''
+  SCM_GIT_BEHIND=''
+  SCM_GIT_STASH=''
+  local status="$(git status -bs --porcelain 2> /dev/null)"
+  if [[ -n "$(grep -v ^# <<< "${status}")" ]]; then
     SCM_DIRTY=1
-     SCM_STATE=${GIT_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY}
+    SCM_STATE=${GIT_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY}
   else
     SCM_DIRTY=0
-     SCM_STATE=${GIT_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN}
+    SCM_STATE=${GIT_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN}
   fi
   SCM_PREFIX=${GIT_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX}
   SCM_SUFFIX=${GIT_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX}
   local ref=$(git symbolic-ref HEAD 2> /dev/null)
   SCM_BRANCH=${ref#refs/heads/}
   SCM_CHANGE=$(git rev-parse HEAD 2>/dev/null)
+  local ahead_re='.+ahead ([0-9]+).+'
+  local behind_re='.+behind ([0-9]+).+'
+  [[ "${status}" =~ ${ahead_re} ]] && SCM_GIT_AHEAD=" ${SCM_GIT_AHEAD_CHAR}${BASH_REMATCH[1]}"
+  [[ "${status}" =~ ${behind_re} ]] && SCM_GIT_BEHIND=" ${SCM_GIT_BEHIND_CHAR}${BASH_REMATCH[1]}"
+  local stash_count="$(git stash list | wc -l)"
+  [[ "${stash_count}" -gt 0 ]] && SCM_GIT_STASH=" {${stash_count}}"
 }
 
 function svn_prompt_vars {
diff --git a/themes/powerline-plain/powerline-plain.theme.bash b/themes/powerline-plain/powerline-plain.theme.bash
new file mode 100644
index 0000000..4a83513
--- /dev/null
+++ b/themes/powerline-plain/powerline-plain.theme.bash
@@ -0,0 +1,93 @@
+#!/usr/bin/env bash
+
+SHELL_SSH_CHAR="⌁ "
+SHELL_THEME_PROMPT_COLOR=32
+SHELL_SSH_THEME_PROMPT_COLOR=208
+
+VIRTUALENV_CHAR="ⓔ "
+VIRTUALENV_THEME_PROMPT_COLOR=35
+
+SCM_NONE_CHAR=""
+SCM_GIT_CHAR="⎇  "
+SCM_GIT_BEHIND_CHAR="↓"
+SCM_GIT_AHEAD_CHAR="↑"
+SCM_THEME_PROMPT_CLEAN=""
+SCM_THEME_PROMPT_DIRTY=""
+SCM_THEME_PROMPT_COLOR=238
+SCM_THEME_PROMPT_CLEAN_COLOR=231
+SCM_THEME_PROMPT_DIRTY_COLOR=220
+
+CWD_THEME_PROMPT_COLOR=240
+
+LAST_STATUS_THEME_PROMPT_COLOR=52
+
+function set_rgb_color {
+    if [[ "${1}" != "-" ]]; then
+        fg="38;5;${1}"
+    fi
+    if [[ "${2}" != "-" ]]; then
+        bg="48;5;${2}"
+        [[ -n "${fg}" ]] && bg=";${bg}"
+    fi
+    echo -e "\[\033[${fg}${bg}m\]"
+}
+
+function powerline_shell_prompt {
+    if [[ -n "${SSH_CLIENT}" ]]; then
+        SHELL_PROMPT="${bold_white}$(set_rgb_color - ${SHELL_SSH_THEME_PROMPT_COLOR}) ${SHELL_SSH_CHAR}\u@\h ${normal}"
+    else
+        SHELL_PROMPT="${bold_white}$(set_rgb_color - ${SHELL_THEME_PROMPT_COLOR}) \u ${normal}"
+    fi
+}
+
+function powerline_virtualenv_prompt {
+    if [[ -n "$VIRTUAL_ENV" ]]; then
+        virtualenv=$(basename "$VIRTUAL_ENV")
+        VIRTUALENV_PROMPT="$(set_rgb_color - ${VIRTUALENV_THEME_PROMPT_COLOR}) ${VIRTUALENV_CHAR}$virtualenv ${normal}"
+    else
+        VIRTUALENV_PROMPT=""
+    fi
+}
+
+function powerline_scm_prompt {
+    scm_prompt_vars
+
+    if [[ "${SCM_NONE_CHAR}" != "${SCM_CHAR}" ]]; then
+        if [[ "${SCM_DIRTY}" -eq 1 ]]; then
+            SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_DIRTY_COLOR} ${SCM_THEME_PROMPT_COLOR})"
+        else
+            SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_CLEAN_COLOR} ${SCM_THEME_PROMPT_COLOR})"
+        fi
+        [[ "${SCM_GIT_CHAR}" == "${SCM_CHAR}" ]] && SCM_PROMPT+=" ${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}${SCM_GIT_BEHIND}${SCM_GIT_AHEAD}${SCM_GIT_STASH}"
+        SCM_PROMPT="${SCM_PROMPT} ${normal}"
+    else
+        SCM_PROMPT=""
+    fi
+}
+
+function powerline_cwd_prompt {
+    CWD_PROMPT="${THEME_PROMPT_SEPARATOR}${normal}$(set_rgb_color - ${CWD_THEME_PROMPT_COLOR}) \w ${normal}$(set_rgb_color ${CWD_THEME_PROMPT_COLOR} -)${normal}"
+}
+
+function powerline_last_status_prompt {
+    if [[ "$1" -eq 0 ]]; then
+        LAST_STATUS_PROMPT=""
+    else
+        LAST_STATUS_PROMPT="$(set_rgb_color - ${LAST_STATUS_THEME_PROMPT_COLOR}) ${LAST_STATUS} ${normal}$(set_rgb_color ${LAST_STATUS_THEME_PROMPT_COLOR} -)${THEME_PROMPT_SEPARATOR}${normal}"
+    fi
+}
+
+function powerline_prompt_command() {
+    local LAST_STATUS="$?"
+
+    powerline_shell_prompt
+    powerline_virtualenv_prompt
+    powerline_scm_prompt
+    powerline_cwd_prompt
+    powerline_last_status_prompt LAST_STATUS
+
+    PS1="${SHELL_PROMPT}${VIRTUALENV_PROMPT}${SCM_PROMPT}${CWD_PROMPT}${LAST_STATUS_PROMPT} "
+}
+
+PROMPT_COMMAND=powerline_prompt_command
+
diff --git a/themes/powerline/powerline.theme.bash b/themes/powerline/powerline.theme.bash
new file mode 100644
index 0000000..a67463a
--- /dev/null
+++ b/themes/powerline/powerline.theme.bash
@@ -0,0 +1,100 @@
+#!/usr/bin/env bash
+
+THEME_PROMPT_SEPARATOR=""
+
+SHELL_SSH_CHAR=" "
+SHELL_THEME_PROMPT_COLOR=32
+SHELL_SSH_THEME_PROMPT_COLOR=208
+
+VIRTUALENV_CHAR="ⓔ "
+VIRTUALENV_THEME_PROMPT_COLOR=35
+
+SCM_NONE_CHAR=""
+SCM_GIT_CHAR=" "
+SCM_GIT_BEHIND_CHAR="↓"
+SCM_GIT_AHEAD_CHAR="↑"
+SCM_THEME_PROMPT_CLEAN=""
+SCM_THEME_PROMPT_DIRTY=""
+SCM_THEME_PROMPT_COLOR=238
+SCM_THEME_PROMPT_CLEAN_COLOR=231
+SCM_THEME_PROMPT_DIRTY_COLOR=220
+
+CWD_THEME_PROMPT_COLOR=240
+
+LAST_STATUS_THEME_PROMPT_COLOR=52
+
+function set_rgb_color {
+    if [[ "${1}" != "-" ]]; then
+        fg="38;5;${1}"
+    fi
+    if [[ "${2}" != "-" ]]; then
+        bg="48;5;${2}"
+        [[ -n "${fg}" ]] && bg=";${bg}"
+    fi
+    echo -e "\[\033[${fg}${bg}m\]"
+}
+
+function powerline_shell_prompt {
+    if [[ -n "${SSH_CLIENT}" ]]; then
+        SHELL_PROMPT="${bold_white}$(set_rgb_color - ${SHELL_SSH_THEME_PROMPT_COLOR}) ${SHELL_SSH_CHAR}\u@\h ${normal}"
+        LAST_THEME_COLOR=${SHELL_SSH_THEME_PROMPT_COLOR}
+    else
+        SHELL_PROMPT="${bold_white}$(set_rgb_color - ${SHELL_THEME_PROMPT_COLOR}) \u ${normal}"
+        LAST_THEME_COLOR=${SHELL_THEME_PROMPT_COLOR}
+    fi
+}
+
+function powerline_virtualenv_prompt {
+    if [[ -n "$VIRTUAL_ENV" ]]; then
+        virtualenv=$(basename "$VIRTUAL_ENV")
+        VIRTUALENV_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${VIRTUALENV_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}$(set_rgb_color - ${VIRTUALENV_THEME_PROMPT_COLOR}) ${VIRTUALENV_CHAR}$virtualenv ${normal}"
+        LAST_THEME_COLOR=${VIRTUALENV_THEME_PROMPT_COLOR}
+    else
+        VIRTUALENV_PROMPT=""
+    fi
+}
+
+function powerline_scm_prompt {
+    scm_prompt_vars
+
+    if [[ "${SCM_NONE_CHAR}" != "${SCM_CHAR}" ]]; then
+        if [[ "${SCM_DIRTY}" -eq 1 ]]; then
+            SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_DIRTY_COLOR} ${SCM_THEME_PROMPT_COLOR})"
+        else
+            SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_CLEAN_COLOR} ${SCM_THEME_PROMPT_COLOR})"
+        fi
+        [[ "${SCM_GIT_CHAR}" == "${SCM_CHAR}" ]] && SCM_PROMPT+=" ${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}${SCM_GIT_BEHIND}${SCM_GIT_AHEAD}${SCM_GIT_STASH}"
+        SCM_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${SCM_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}${SCM_PROMPT} ${normal}"
+        LAST_THEME_COLOR=${SCM_THEME_PROMPT_COLOR}
+    else
+        SCM_PROMPT=""
+    fi
+}
+
+function powerline_cwd_prompt {
+    CWD_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${CWD_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}$(set_rgb_color - ${CWD_THEME_PROMPT_COLOR}) \w ${normal}$(set_rgb_color ${CWD_THEME_PROMPT_COLOR} -)${normal}"
+    LAST_THEME_COLOR=${CWD_THEME_PROMPT_COLOR}
+}
+
+function powerline_last_status_prompt {
+    if [[ "$1" -eq 0 ]]; then
+        LAST_STATUS_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} -)${THEME_PROMPT_SEPARATOR}${normal}"
+    else
+        LAST_STATUS_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${LAST_STATUS_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}$(set_rgb_color - ${LAST_STATUS_THEME_PROMPT_COLOR}) ${LAST_STATUS} ${normal}$(set_rgb_color ${LAST_STATUS_THEME_PROMPT_COLOR} -)${THEME_PROMPT_SEPARATOR}${normal}"
+    fi
+}
+
+function powerline_prompt_command() {
+    local LAST_STATUS="$?"
+
+    powerline_shell_prompt
+    powerline_virtualenv_prompt
+    powerline_scm_prompt
+    powerline_cwd_prompt
+    powerline_last_status_prompt LAST_STATUS
+
+    PS1="${SHELL_PROMPT}${VIRTUALENV_PROMPT}${SCM_PROMPT}${CWD_PROMPT}${LAST_STATUS_PROMPT} "
+}
+
+PROMPT_COMMAND=powerline_prompt_command
+