Nils Winkler | 460382a | 2013-11-07 14:08:42 +0100 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Two line prompt showing the following information: |
| 4 | # (time) SCM [username@hostname] pwd (SCM branch SCM status) |
| 5 | # → |
| 6 | # |
| 7 | # Example: |
| 8 | # (14:00:26) ± [foo@bar] ~/.bash_it (master ✓) |
| 9 | # → |
| 10 | # |
| 11 | # The arrow on the second line is showing the exit status of the last command: |
| 12 | # * Green: 0 exit status |
| 13 | # * Red: non-zero exit status |
| 14 | # |
| 15 | # The exit code functionality currently doesn't work if you are using the 'fasd' plugin, |
| 16 | # since 'fasd' is messing with the $PROMPT_COMMAND |
| 17 | |
| 18 | |
| 19 | PROMPT_END_CLEAN="${green}→${reset_color}" |
| 20 | PROMPT_END_DIRTY="${red}→${reset_color}" |
| 21 | |
| 22 | function prompt_end() { |
| 23 | echo -e "$PROMPT_END" |
| 24 | } |
| 25 | |
| 26 | prompt_setter() { |
| 27 | local exit_status=$? |
| 28 | if [[ $exit_status -eq 0 ]]; then PROMPT_END=$PROMPT_END_CLEAN |
| 29 | else PROMPT_END=$PROMPT_END_DIRTY |
| 30 | fi |
| 31 | # Save history |
| 32 | history -a |
| 33 | history -c |
| 34 | history -r |
| 35 | PS1="(\t) $(scm_char) [${blue}\u${reset_color}@${green}\H${reset_color}] ${yellow}\w${reset_color}$(scm_prompt_info) ${reset_color}\n$(prompt_end) " |
| 36 | PS2='> ' |
| 37 | PS4='+ ' |
| 38 | } |
| 39 | |
| 40 | PROMPT_COMMAND=prompt_setter |
| 41 | |
| 42 | SCM_THEME_PROMPT_DIRTY=" ${bold_red}✗${normal}" |
| 43 | SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓${normal}" |
| 44 | SCM_THEME_PROMPT_PREFIX=" (" |
| 45 | SCM_THEME_PROMPT_SUFFIX=")" |
| 46 | RVM_THEME_PROMPT_PREFIX=" (" |
| 47 | RVM_THEME_PROMPT_SUFFIX=")" |