blob: 2b39b955bebea404fa9a759950493f11847533d9 [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#
10# by Jesus de Mula <jesus@demula.name>
11
12# For the real Monokai colors you should add these to your .XDefaults or
13# terminal configuration:
14#! ----------------------------------------------------------- TERMINAL COLORS
15#! monokai - http://www.monokai.nl/blog/2006/07/15/textmate-color-theme/
16#*background: #272822
17#*foreground: #E2DA6E
18#*color0: black
19#! mild red
20#*color1: #CD0000
21#! light green
22#*color2: #A5E02D
23#! orange (yellow)
24#*color3: #FB951F
25#! "dark" blue
26#*color4: #076BCC
27#! hot pink
28#*color5: #F6266C
29#! cyan
30#*color6: #64D9ED
31#! gray
32#*color7: #E5E5E5
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +010033
34# ----------------------------------------------------------------- COLOR CONF
35D_DEFAULT_COLOR='\[${normal}\]'
36D_INTERMEDIATE_COLOR='\[${white}\]'
37D_USER_COLOR='\[${purple}\]'
38D_SUPERUSER_COLOR='\[${red}\]'
39D_MACHINE_COLOR='\[${cyan}\]'
40D_DIR_COLOR='\[${green}\]'
41D_SCM_COLOR='\[${yellow}\]'
42D_BRANCH_COLOR='\[${yellow}\]'
43D_CHANGES_COLOR='\[${white}\]'
44D_CMDFAIL_COLOR='\[${red}\]'
45D_VIMSHELL_COLOR='\[${cyan}\]'
Jesus de Mula Cano0127dc22011-03-06 18:49:08 +010046
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +010047# ------------------------------------------------------------------ FUNCTIONS
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +010048case $TERM in
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +010049 xterm*)
50 TITLEBAR="\[\033]0;\w\007\]"
51 ;;
52 *)
53 TITLEBAR=""
54 ;;
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +010055esac
56
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +010057is_vim_shell() {
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +010058 if [ ! -z "$VIMRUNTIME" ]
59 then
60 echo "${D_INTERMEDIATE_COLOR}on ${D_VIMSHELL_COLOR}\
61vim shell${D_DEFAULT_COLOR} "
62 fi
63}
64
65demula_battery_charge() {
66 if [ ! -z "$(battery_charge)" ]
67 then
68 battery_charge
69 fi
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +010070}
71
72mitsuhikos_lastcommandfailed() {
73 code=$?
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +010074 if [ $code != 0 ];
75 then
76 echo "${D_INTERMEDIATE_COLOR}exited ${D_CMDFAIL_COLOR}\
77$code ${D_DEFAULT_COLOR}"
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +010078 fi
79}
80
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +010081# vcprompt for scm instead of bash_it default
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +010082demula_vcprompt() {
Jesus de Mula Cano0127dc22011-03-06 18:49:08 +010083 if [ ! -z "$VCPROMPT_EXECUTABLE" ]
84 then
85 local D_VCPROMPT_FORMAT="on ${D_SCM_COLOR}%s${D_INTERMEDIATE_COLOR}:\
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +010086${D_BRANCH_COLOR}%b %r ${D_CHANGES_COLOR}%m%u ${D_DEFAULT_COLOR}"
Jesus de Mula Cano0127dc22011-03-06 18:49:08 +010087 $VCPROMPT_EXECUTABLE -f "$D_VCPROMPT_FORMAT"
88 fi
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +010089}
90
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +010091# -------------------------------------------------------------- PROMPT OUTPUT
92prompt() {
93 local SAVE_CURSOR='\[\033[s\]'
94 local RESTORE_CURSOR='\[\033[u\]'
95 local MOVE_CURSOR_RIGHTMOST='\[\033[500C\]'
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +010096 local MOVE_CURSOR_5_LEFT='\[\033[5D\]'
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +010097
98 PS1="${TITLEBAR}\n\
99${SAVE_CURSOR}${MOVE_CURSOR_RIGHTMOST}${MOVE_CURSOR_5_LEFT}\
100$(demula_battery_charge)${RESTORE_CURSOR}\
101${D_USER_COLOR}\u ${D_INTERMEDIATE_COLOR}\
102at ${D_MACHINE_COLOR}\h ${D_INTERMEDIATE_COLOR}\
103in ${D_DIR_COLOR}\w ${D_INTERMEDIATE_COLOR}\
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +0100104$(mitsuhikos_lastcommandfailed)\
105$(demula_vcprompt)\
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +0100106$(is_vim_shell)\n\
107${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}"
108
109 PS2="${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}"
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +0100110}
111
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +0100112# Runs prompt (this bypasses bash_it $PROMPT setting)
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +0100113PROMPT_COMMAND=prompt
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +0100114