blob: e8b3bc2ba67d3856828dc4764f0f8a9ad9a189de [file] [log] [blame]
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +01001#!/bin/bash
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +01002
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +01003# Theme inspired on:
4# - Ronacher's dotfiles (mitsuhikos) - http://github.com/mitsuhiko/dotfiles/tree/master/bash/
5# - Glenbot - http://theglenbot.com/custom-bash-shell-for-development/
6# - My extravagant zsh - http://stevelosh.com/blog/2010/02/my-extravagant-zsh-prompt/
7# - Monokai colors - http://monokai.nl/blog/2006/07/15/textmate-color-theme/
Jesus de Mula Cano0127dc22011-03-06 18:49:08 +01008# - Bash_it modern theme
9#
Jesus de Mula Cano23de53a2011-03-06 22:37:47 +010010# Screenshot: http://goo.gl/VCmX5
Jesus de Mula Cano0127dc22011-03-06 18:49:08 +010011# by Jesus de Mula <jesus@demula.name>
12
13# For the real Monokai colors you should add these to your .XDefaults or
14# terminal configuration:
15#! ----------------------------------------------------------- TERMINAL COLORS
16#! monokai - http://www.monokai.nl/blog/2006/07/15/textmate-color-theme/
17#*background: #272822
18#*foreground: #E2DA6E
19#*color0: black
20#! mild red
21#*color1: #CD0000
22#! light green
23#*color2: #A5E02D
24#! orange (yellow)
25#*color3: #FB951F
26#! "dark" blue
27#*color4: #076BCC
28#! hot pink
29#*color5: #F6266C
30#! cyan
31#*color6: #64D9ED
32#! gray
33#*color7: #E5E5E5
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +010034
35# ----------------------------------------------------------------- COLOR CONF
36D_DEFAULT_COLOR='\[${normal}\]'
37D_INTERMEDIATE_COLOR='\[${white}\]'
38D_USER_COLOR='\[${purple}\]'
39D_SUPERUSER_COLOR='\[${red}\]'
40D_MACHINE_COLOR='\[${cyan}\]'
41D_DIR_COLOR='\[${green}\]'
42D_SCM_COLOR='\[${yellow}\]'
43D_BRANCH_COLOR='\[${yellow}\]'
44D_CHANGES_COLOR='\[${white}\]'
45D_CMDFAIL_COLOR='\[${red}\]'
46D_VIMSHELL_COLOR='\[${cyan}\]'
Jesus de Mula Cano0127dc22011-03-06 18:49:08 +010047
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +010048# ------------------------------------------------------------------ FUNCTIONS
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +010049case $TERM in
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +010050 xterm*)
51 TITLEBAR="\[\033]0;\w\007\]"
52 ;;
53 *)
54 TITLEBAR=""
55 ;;
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +010056esac
57
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +010058is_vim_shell() {
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +010059 if [ ! -z "$VIMRUNTIME" ]
60 then
61 echo "${D_INTERMEDIATE_COLOR}on ${D_VIMSHELL_COLOR}\
62vim shell${D_DEFAULT_COLOR} "
63 fi
64}
65
66demula_battery_charge() {
67 if [ ! -z "$(battery_charge)" ]
68 then
69 battery_charge
70 fi
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +010071}
72
73mitsuhikos_lastcommandfailed() {
74 code=$?
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +010075 if [ $code != 0 ];
76 then
77 echo "${D_INTERMEDIATE_COLOR}exited ${D_CMDFAIL_COLOR}\
78$code ${D_DEFAULT_COLOR}"
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +010079 fi
80}
81
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +010082# vcprompt for scm instead of bash_it default
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +010083demula_vcprompt() {
Jesus de Mula Cano0127dc22011-03-06 18:49:08 +010084 if [ ! -z "$VCPROMPT_EXECUTABLE" ]
85 then
86 local D_VCPROMPT_FORMAT="on ${D_SCM_COLOR}%s${D_INTERMEDIATE_COLOR}:\
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +010087${D_BRANCH_COLOR}%b %r ${D_CHANGES_COLOR}%m%u ${D_DEFAULT_COLOR}"
Jesus de Mula Cano0127dc22011-03-06 18:49:08 +010088 $VCPROMPT_EXECUTABLE -f "$D_VCPROMPT_FORMAT"
89 fi
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +010090}
91
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +010092# -------------------------------------------------------------- PROMPT OUTPUT
93prompt() {
94 local SAVE_CURSOR='\[\033[s\]'
95 local RESTORE_CURSOR='\[\033[u\]'
96 local MOVE_CURSOR_RIGHTMOST='\[\033[500C\]'
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +010097 local MOVE_CURSOR_5_LEFT='\[\033[5D\]'
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +010098
99 PS1="${TITLEBAR}\n\
100${SAVE_CURSOR}${MOVE_CURSOR_RIGHTMOST}${MOVE_CURSOR_5_LEFT}\
101$(demula_battery_charge)${RESTORE_CURSOR}\
102${D_USER_COLOR}\u ${D_INTERMEDIATE_COLOR}\
103at ${D_MACHINE_COLOR}\h ${D_INTERMEDIATE_COLOR}\
104in ${D_DIR_COLOR}\w ${D_INTERMEDIATE_COLOR}\
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +0100105$(mitsuhikos_lastcommandfailed)\
106$(demula_vcprompt)\
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +0100107$(is_vim_shell)\n\
108${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}"
109
110 PS2="${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}"
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +0100111}
112
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +0100113# Runs prompt (this bypasses bash_it $PROMPT setting)
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +0100114PROMPT_COMMAND=prompt
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +0100115