blob: 87ced7ed0b50124a19d37fef3e87242d4b14b7f8 [file] [log] [blame]
Eitan Adler3fc60b52012-04-17 00:24:58 -04001#!/usr/bin/env bash
Karl Swedberg8ac6e442011-02-27 17:54:35 -05002SCM_THEME_PROMPT_DIRTY=''
3SCM_THEME_PROMPT_CLEAN=''
JFSIII1b7c9412011-06-17 19:45:21 -04004SCM_GIT_CHAR="${bold_cyan}±${normal}"
5SCM_SVN_CHAR="${bold_cyan}⑆${normal}"
6SCM_HG_CHAR="${bold_red}☿${normal}"
Karl Swedberg8ac6e442011-02-27 17:54:35 -05007SCM_THEME_PROMPT_PREFIX=""
8SCM_THEME_PROMPT_SUFFIX=""
Travis Swicegood41ca5672011-07-23 21:48:07 -05009if [ ! -z $RVM_THEME_PROMPT_COLOR ]; then
10 RVM_THEME_PROMPT_COLOR=$(eval echo $`echo ${RVM_THEME_PROMPT_COLOR}`);
11else
12 RVM_THEME_PROMPT_COLOR="${red}"
13fi
14RVM_THEME_PROMPT_PREFIX="(${RVM_THEME_PROMPT_COLOR}rb${normal}: "
Travis Swicegood11995c12011-07-23 21:42:48 -050015RVM_THEME_PROMPT_SUFFIX=") "
Travis Swicegood41ca5672011-07-23 21:48:07 -050016if [ ! -z $VIRTUALENV_THEME_PROMPT_COLOR ]; then
17 VIRTUALENV_THEME_PROMPT_COLOR=$(eval echo $`echo ${VIRTUALENV_THEME_PROMPT_COLOR}`);
18else
19 VIRTUALENV_THEME_PROMPT_COLOR="${green}"
20fi
21VIRTUALENV_THEME_PROMPT_PREFIX="(${VIRTUALENV_THEME_PROMPT_COLOR}py${normal}: "
Travis Swicegood11995c12011-07-23 21:42:48 -050022VIRTUALENV_THEME_PROMPT_SUFFIX=") "
Karl Swedberg8ac6e442011-02-27 17:54:35 -050023
Travis Swicegood1638a1a2011-02-28 14:18:46 -060024if [ ! -z $THEME_PROMPT_HOST_COLOR ]; then
25 THEME_PROMPT_HOST_COLOR=$(eval echo $`echo ${THEME_PROMPT_HOST_COLOR}`);
26else
27 THEME_PROMPT_HOST_COLOR="$blue"
28fi
29
Karl Swedberg8ac6e442011-02-27 17:54:35 -050030doubletime_scm_prompt() {
31 CHAR=$(scm_char)
Jeff Carouth6e8733e2011-06-25 10:05:25 -050032 if [ $CHAR = $SCM_NONE_CHAR ]; then
Karl Swedberg8ac6e442011-02-27 17:54:35 -050033 return
Jeff Carouth6e8733e2011-06-25 10:05:25 -050034 elif [ $CHAR = $SCM_GIT_CHAR ]; then
Karl Swedberg8ac6e442011-02-27 17:54:35 -050035 echo "$(git_prompt_status)"
Jeff Carouth6e8733e2011-06-25 10:05:25 -050036 else
37 echo "[$(scm_prompt_info)]"
Karl Swedberg8ac6e442011-02-27 17:54:35 -050038 fi
39}
40
JFSIII1b7c9412011-06-17 19:45:21 -040041function prompt_setter() {
Karl Swedberg8ac6e442011-02-27 17:54:35 -050042 # Save history
43 history -a
44 history -c
45 history -r
Travis Swicegood9623fd42011-05-30 10:12:51 -050046 if [[ -z "$THEME_PROMPT_CLOCK_FORMAT" ]]
47 then
48 clock="\t"
49 else
50 clock=$THEME_PROMPT_CLOCK_FORMAT
51 fi
Karl Swedberg8ac6e442011-02-27 17:54:35 -050052 PS1="
Hendrik Mans1be44672012-01-26 16:07:06 +010053$clock $(scm_char) [$THEME_PROMPT_HOST_COLOR\u@${THEME_PROMPT_HOST}$reset_color] $(virtualenv_prompt)$(ruby_version_prompt)\w
JFSIII1b7c9412011-06-17 19:45:21 -040054$(doubletime_scm_prompt)$reset_color $ "
Karl Swedberg8ac6e442011-02-27 17:54:35 -050055 PS2='> '
56 PS4='+ '
57}
58
59PROMPT_COMMAND=prompt_setter
60
61git_prompt_status() {
Travis Swicegoodb7e429b2012-05-01 17:25:47 -050062 local git_status_output
63 git_status_output=$(git status 2> /dev/null )
64 if [ -n "$(echo $git_status_output | grep 'Changes not staged')" ]; then
Karl Swedberg8ac6e442011-02-27 17:54:35 -050065 git_status="${bold_red}$(scm_prompt_info) ✗"
Travis Swicegoodb7e429b2012-05-01 17:25:47 -050066 elif [ -n "$(echo $git_status_output | grep 'Changes to be committed')" ]; then
Karl Swedberg8ac6e442011-02-27 17:54:35 -050067 git_status="${bold_yellow}$(scm_prompt_info) ^"
Travis Swicegoodb7e429b2012-05-01 17:25:47 -050068 elif [ -n "$(echo $git_status_output | grep 'Untracked files')" ]; then
Karl Swedberg8ac6e442011-02-27 17:54:35 -050069 git_status="${bold_cyan}$(scm_prompt_info) +"
Travis Swicegoodb7e429b2012-05-01 17:25:47 -050070 elif [ -n "$(echo $git_status_output | grep 'nothing to commit')" ]; then
Karl Swedberg8ac6e442011-02-27 17:54:35 -050071 git_status="${bold_green}$(scm_prompt_info) ${green}✓"
72 else
73 git_status="$(scm_prompt_info)"
74 fi
75 echo "[$git_status${normal}]"
76
77}