Eduardo Bellido Bellido | 68dc676 | 2013-11-13 00:01:09 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | THEME_PROMPT_SEPARATOR="" |
| 4 | |
| 5 | SHELL_SSH_CHAR=" " |
| 6 | SHELL_THEME_PROMPT_COLOR=32 |
| 7 | SHELL_SSH_THEME_PROMPT_COLOR=208 |
| 8 | |
| 9 | VIRTUALENV_CHAR="ⓔ " |
| 10 | VIRTUALENV_THEME_PROMPT_COLOR=35 |
| 11 | |
| 12 | SCM_NONE_CHAR="" |
| 13 | SCM_GIT_CHAR=" " |
| 14 | SCM_GIT_BEHIND_CHAR="↓" |
| 15 | SCM_GIT_AHEAD_CHAR="↑" |
Travis Swicegood | 5141605 | 2014-04-01 10:41:00 -0500 | [diff] [blame] | 16 | if [[ -z "$THEME_SCM_TAG_PREFIX" ]]; then |
| 17 | SCM_TAG_PREFIX="tag > " |
| 18 | else |
| 19 | SCM_TAG_PREFIX="$THEME_SCM_TAG_PREFIX" |
| 20 | fi |
| 21 | |
Eduardo Bellido Bellido | 68dc676 | 2013-11-13 00:01:09 +0100 | [diff] [blame] | 22 | SCM_THEME_PROMPT_CLEAN="" |
| 23 | SCM_THEME_PROMPT_DIRTY="" |
| 24 | SCM_THEME_PROMPT_COLOR=238 |
Eduardo Bellido Bellido | 91538bc | 2013-11-15 20:57:27 +0100 | [diff] [blame] | 25 | SCM_THEME_PROMPT_CLEAN_COLOR=231 |
Travis Swicegood | 16704a6 | 2013-11-25 18:02:58 -0600 | [diff] [blame] | 26 | SCM_THEME_PROMPT_DIRTY_COLOR=196 |
| 27 | SCM_THEME_PROMPT_STAGED_COLOR=220 |
| 28 | SCM_THEME_PROMPT_UNTRACKED_COLOR=033 |
Eduardo Bellido Bellido | 68dc676 | 2013-11-13 00:01:09 +0100 | [diff] [blame] | 29 | |
| 30 | CWD_THEME_PROMPT_COLOR=240 |
| 31 | |
| 32 | LAST_STATUS_THEME_PROMPT_COLOR=52 |
| 33 | |
| 34 | function set_rgb_color { |
| 35 | if [[ "${1}" != "-" ]]; then |
| 36 | fg="38;5;${1}" |
| 37 | fi |
| 38 | if [[ "${2}" != "-" ]]; then |
| 39 | bg="48;5;${2}" |
| 40 | [[ -n "${fg}" ]] && bg=";${bg}" |
| 41 | fi |
| 42 | echo -e "\[\033[${fg}${bg}m\]" |
| 43 | } |
| 44 | |
| 45 | function powerline_shell_prompt { |
| 46 | if [[ -n "${SSH_CLIENT}" ]]; then |
| 47 | SHELL_PROMPT="${bold_white}$(set_rgb_color - ${SHELL_SSH_THEME_PROMPT_COLOR}) ${SHELL_SSH_CHAR}\u@\h ${normal}" |
| 48 | LAST_THEME_COLOR=${SHELL_SSH_THEME_PROMPT_COLOR} |
| 49 | else |
| 50 | SHELL_PROMPT="${bold_white}$(set_rgb_color - ${SHELL_THEME_PROMPT_COLOR}) \u ${normal}" |
| 51 | LAST_THEME_COLOR=${SHELL_THEME_PROMPT_COLOR} |
| 52 | fi |
| 53 | } |
| 54 | |
| 55 | function powerline_virtualenv_prompt { |
| 56 | if [[ -n "$VIRTUAL_ENV" ]]; then |
| 57 | virtualenv=$(basename "$VIRTUAL_ENV") |
| 58 | 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}" |
| 59 | LAST_THEME_COLOR=${VIRTUALENV_THEME_PROMPT_COLOR} |
| 60 | else |
| 61 | VIRTUALENV_PROMPT="" |
| 62 | fi |
| 63 | } |
| 64 | |
| 65 | function powerline_scm_prompt { |
| 66 | scm_prompt_vars |
Travis Swicegood | 16704a6 | 2013-11-25 18:02:58 -0600 | [diff] [blame] | 67 | local git_status_output |
| 68 | git_status_output=$(git status 2> /dev/null ) |
Eduardo Bellido Bellido | 68dc676 | 2013-11-13 00:01:09 +0100 | [diff] [blame] | 69 | |
| 70 | if [[ "${SCM_NONE_CHAR}" != "${SCM_CHAR}" ]]; then |
| 71 | if [[ "${SCM_DIRTY}" -eq 1 ]]; then |
Travis Swicegood | 16704a6 | 2013-11-25 18:02:58 -0600 | [diff] [blame] | 72 | if [ -n "$(echo $git_status_output | grep 'Changes not staged')" ]; then |
| 73 | SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_DIRTY_COLOR} ${SCM_THEME_PROMPT_COLOR})" |
| 74 | elif [ -n "$(echo $git_status_output | grep 'Changes to be committed')" ]; then |
| 75 | SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_STAGED_COLOR} ${SCM_THEME_PROMPT_COLOR})" |
| 76 | elif [ -n "$(echo $git_status_output | grep 'Untracked files')" ]; then |
| 77 | SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_UNTRACKED_COLOR} ${SCM_THEME_PROMPT_COLOR})" |
Travis Swicegood | 1a885b9 | 2013-11-25 18:06:33 -0600 | [diff] [blame] | 78 | else |
| 79 | SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_DIRTY_COLOR} ${SCM_THEME_PROMPT_COLOR})" |
Travis Swicegood | 16704a6 | 2013-11-25 18:02:58 -0600 | [diff] [blame] | 80 | fi |
Eduardo Bellido Bellido | 68dc676 | 2013-11-13 00:01:09 +0100 | [diff] [blame] | 81 | else |
| 82 | SCM_PROMPT="$(set_rgb_color ${SCM_THEME_PROMPT_CLEAN_COLOR} ${SCM_THEME_PROMPT_COLOR})" |
| 83 | fi |
Travis Swicegood | 5141605 | 2014-04-01 10:41:00 -0500 | [diff] [blame] | 84 | if [[ "${SCM_GIT_CHAR}" == "${SCM_CHAR}" ]]; then |
| 85 | local tag="" |
| 86 | if [[ $SCM_IS_TAG -eq "1" ]]; then |
| 87 | tag=$SCM_TAG_PREFIX |
| 88 | fi |
| 89 | SCM_PROMPT+=" ${SCM_CHAR}${tag}${SCM_BRANCH}${SCM_STATE}${SCM_GIT_BEHIND}${SCM_GIT_AHEAD}${SCM_GIT_STASH}" |
| 90 | fi |
Eduardo Bellido Bellido | 68dc676 | 2013-11-13 00:01:09 +0100 | [diff] [blame] | 91 | SCM_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} ${SCM_THEME_PROMPT_COLOR})${THEME_PROMPT_SEPARATOR}${normal}${SCM_PROMPT} ${normal}" |
| 92 | LAST_THEME_COLOR=${SCM_THEME_PROMPT_COLOR} |
| 93 | else |
| 94 | SCM_PROMPT="" |
| 95 | fi |
| 96 | } |
| 97 | |
| 98 | function powerline_cwd_prompt { |
| 99 | 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}" |
| 100 | LAST_THEME_COLOR=${CWD_THEME_PROMPT_COLOR} |
| 101 | } |
| 102 | |
| 103 | function powerline_last_status_prompt { |
| 104 | if [[ "$1" -eq 0 ]]; then |
| 105 | LAST_STATUS_PROMPT="$(set_rgb_color ${LAST_THEME_COLOR} -)${THEME_PROMPT_SEPARATOR}${normal}" |
| 106 | else |
| 107 | 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}" |
| 108 | fi |
| 109 | } |
| 110 | |
| 111 | function powerline_prompt_command() { |
| 112 | local LAST_STATUS="$?" |
| 113 | |
| 114 | powerline_shell_prompt |
| 115 | powerline_virtualenv_prompt |
| 116 | powerline_scm_prompt |
| 117 | powerline_cwd_prompt |
| 118 | powerline_last_status_prompt LAST_STATUS |
| 119 | |
| 120 | PS1="${SHELL_PROMPT}${VIRTUALENV_PROMPT}${SCM_PROMPT}${CWD_PROMPT}${LAST_STATUS_PROMPT} " |
| 121 | } |
| 122 | |
| 123 | PROMPT_COMMAND=powerline_prompt_command |
| 124 | |