blob: a0f35bf680369b1312a2844a6e598aab58e26943 [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/
8# - Docs of Bash - http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x361.html
9
10# ----------------------------------------------------------------- COLOR CONF
11D_DEFAULT_COLOR='\[${normal}\]'
12D_INTERMEDIATE_COLOR='\[${white}\]'
13D_USER_COLOR='\[${purple}\]'
14D_SUPERUSER_COLOR='\[${red}\]'
15D_MACHINE_COLOR='\[${cyan}\]'
16D_DIR_COLOR='\[${green}\]'
17D_SCM_COLOR='\[${yellow}\]'
18D_BRANCH_COLOR='\[${yellow}\]'
19D_CHANGES_COLOR='\[${white}\]'
20D_CMDFAIL_COLOR='\[${red}\]'
21D_VIMSHELL_COLOR='\[${cyan}\]'
22# ------------------------------------------------------------------ FUNCTIONS
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +010023case $TERM in
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +010024 xterm*)
25 TITLEBAR="\[\033]0;\w\007\]"
26 ;;
27 *)
28 TITLEBAR=""
29 ;;
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +010030esac
31
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +010032is_vim_shell() {
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +010033 if [ ! -z "$VIMRUNTIME" ]
34 then
35 echo "${D_INTERMEDIATE_COLOR}on ${D_VIMSHELL_COLOR}\
36vim shell${D_DEFAULT_COLOR} "
37 fi
38}
39
40demula_battery_charge() {
41 if [ ! -z "$(battery_charge)" ]
42 then
43 battery_charge
44 fi
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +010045}
46
47mitsuhikos_lastcommandfailed() {
48 code=$?
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +010049 if [ $code != 0 ];
50 then
51 echo "${D_INTERMEDIATE_COLOR}exited ${D_CMDFAIL_COLOR}\
52$code ${D_DEFAULT_COLOR}"
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +010053 fi
54}
55
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +010056# vcprompt for scm instead of bash_it default
57# https://github.com/xvzf/vcprompt
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +010058demula_vcprompt() {
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +010059 local D_VCPROMPT_EXECUTABLE=~/.vcprompt/bin/vcprompt
60 local D_VCPROMPT_FORMAT="on ${D_SCM_COLOR}%s${D_INTERMEDIATE_COLOR}:\
61${D_BRANCH_COLOR}%b %r ${D_CHANGES_COLOR}%m%u ${D_DEFAULT_COLOR}"
62 local D_VCPROMPT_OUTPUT=$($D_VCPROMPT_EXECUTABLE -f "$D_VCPROMPT_FORMAT")
63
64 echo $D_VCPROMPT_OUTPUT
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +010065}
66
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +010067
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +010068# -------------------------------------------------------------- PROMPT OUTPUT
69prompt() {
70 local SAVE_CURSOR='\[\033[s\]'
71 local RESTORE_CURSOR='\[\033[u\]'
72 local MOVE_CURSOR_RIGHTMOST='\[\033[500C\]'
73 local MOVE_CURSOR_LEFTMOST='\[\033[500D\]'
74 local MOVE_CURSOR_5_LEFT='\[\033[5D\]'
75 local MOVE_CURSOR_1_DOWN='\[\033[1B\]'
76
77 PS1="${TITLEBAR}\n\
78${SAVE_CURSOR}${MOVE_CURSOR_RIGHTMOST}${MOVE_CURSOR_5_LEFT}\
79$(demula_battery_charge)${RESTORE_CURSOR}\
80${D_USER_COLOR}\u ${D_INTERMEDIATE_COLOR}\
81at ${D_MACHINE_COLOR}\h ${D_INTERMEDIATE_COLOR}\
82in ${D_DIR_COLOR}\w ${D_INTERMEDIATE_COLOR}\
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +010083$(mitsuhikos_lastcommandfailed)\
84$(demula_vcprompt)\
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +010085$(is_vim_shell)\n\
86${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}"
87
88 PS2="${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}"
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +010089}
90
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +010091# Runs prompt (this bypasses bash_it $PROMPT setting)
Jesus de Mula Canoa38012f2011-03-04 11:44:56 +010092PROMPT_COMMAND=prompt
Jesus de Mula Cano9681bae2011-03-06 18:17:17 +010093