Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 8794c17f0d
Fetching contributors…

Cannot retrieve contributors at this time

file 97 lines (75 sloc) 2.678 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
#!/bin/bash

shopt -s histappend # multiple terminals don't clobber each others' history
shopt -s checkwinsize # update LINES and COLUMNS

case "$TERM" in
*-256color)
    alias ssh='TERM=${TERM%-256color} ssh'
    ;;
*)
    POTENTIAL_TERM=${TERM}-256color
    POTENTIAL_TERMINFO=${TERM:0:1}/$POTENTIAL_TERM

    # better to check $(toe -a | awk '{print $1}') maybe?
    BOX_TERMINFO_DIR=/usr/share/terminfo
    [[ -f $BOX_TERMINFO_DIR/$POTENTIAL_TERMINFO ]] && export TERM=$POTENTIAL_TERM

    HOME_TERMINFO_DIR=$HOME/.terminfo
    [[ -f $HOME_TERMINFO_DIR/$POTENTIAL_TERMINFO ]] && export TERM=$POTENTIAL_TERM
    ;;
esac

function is_vcs {
    currdir=${PWD}
    vcs=$1
    
    while [[ -e "$currdir" ]]; do
        if [[ -d "$currdir/.$vcs" ]]; then
            return 0
        else
            currdir=${currdir%/*} # now check parent directory
        fi
    done
    
    return 1
}

VANILLA_PWD="\033[1;37m" # bold white
SVN_PWD="\033[1;48;5;234;38;5;51m" # bold light blue on dark gray
HG_PWD="\033[1;48;5;234;38;5;46m" # bold light green on dark gray
GIT_PWD="\033[1;48;5;234;38;5;196m" # bold red on dark gray
GIT_SVN_PWD="\033[1;48;5;234;38;5;163m" # bold purple on dark gray

function get_vcs_pwd_color {
    VCS_PWD=$VANILLA_PWD

    [[ -d .svn ]] && VCS_PWD=$SVN_PWD
    is_vcs hg && VCS_PWD=$HG_PWD
    is_vcs git && VCS_PWD=$GIT_PWD

    [[ -d .svn ]] && is_vcs git && VCS_PWD=$GIT_SVN_PWD

    echo -e $VCS_PWD
}

function set_color_prompt {
    GREEN='\033[36m'
    WHITE='\033[37;49m'
    BRIGHT_WHITE_ON_DFLT_BG='\033[1;37;49m'
    RESET_FORMATTING='\033[0m'

    PS1_JOBS='(( $(jobs | wc -l) > 0 )) && echo " (\j)"'
    PS1_RVM='(( $(rvm-prompt | wc -l) > 0 )) && echo -e "(\['$WHITE'\]$(rvm-prompt p)\['$BRIGHT_WHITE_ON_DFLT_BG'\]$(rvm-prompt g)\['$RESET_FORMATTING'\]) "'

    # \[ \] are required to tell bash that the escapes do not move the cursor

    PS1="\[$GREEN\]\u@\h"
    PS1=$PS1' '
    PS1=$PS1'\[$(get_vcs_pwd_color)\]\w'
    PS1=$PS1"\[$BRIGHT_WHITE_ON_DFLT_BG\]"
    PS1=$PS1'$('$PS1_JOBS')'
    PS1=$PS1": \[$RESET_FORMATTING\]"

    [[ -s $HOME/.rvm/scripts/rvm ]] && PS1='$('$PS1_RVM')'$PS1
}

case "$TERM" in
screen*|putty*|xterm*)
    set_color_prompt
    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'

    eval $(dircolors -b)
    alias ls='ls --color=auto'
    ;;
*)
    PS1="\u@\h \w: "
    ;;
esac

. $HOME/.bash_aliases
. $HOME/.bash_functions

[[ -f /etc/bash_completion ]] && . /etc/bash_completion
[[ -s $HOME/.rvm/scripts/rvm ]] && . $HOME/.rvm/scripts/rvm
[[ -r $rvm_path/scripts/completion ]] && . $rvm_path/scripts/completion

[[ -f $HOME/.local/sh/.bashrc ]] && . $HOME/.local/sh/.bashrc
Something went wrong with that request. Please try again.