Skip to content
This repository
tree: 0e67838055
Fetching contributors…

Cannot retrieve contributors at this time

file 212 lines (180 sloc) 5.249 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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
## -*- shell-script -*-
## .bashrc -- bash configuration file
## Copyright 2004-2010 by Michal Nazarewicz (mina86/AT/mina86.com)
##

# Not interactive?
[ X"${-#*i}" != X"$-" ] || return

# Include ~/.shellrc
if [ -r ~/.shellrc ]; then
. ~/.shellrc
fi


##
## Prompt
##

# Bash seems to have some problems with TERM=rxvt-unicode, probably
# due to invalid terminfo file or some such. I'll need to investigate
# it further when I have the time.
case "$TERM" in rxvt*)
TERM=xterm
esac


# path
if declare -f tpwd >/dev/null 2>&1; then
P='$(tpwd -n 30 {)'
elif P="$(which tpwd 2>/dev/null)"; then
eval "$("$P" --bash)"
P='$(tpwd -n 30 {)'
else
P='\w'
fi


PS1=
case "$TERM" in
dumb) # EMACS' eshell (no colors)
PS1+='[\u@\h {{GIT}}'"$P"']\$ '
;;
*) # FIXME: I need to check if term sup. colors
if [ x"$TERM" != xeterm ]; then
__sp=
PS1+='\[\e[0;37;44m\]['
if [ $UID -eq 0 ]; then
PS1+='\[\e[1;31;44m\]\u\[\e[1;37;44m\]'
__sp=' '
fi
if [ -n "$SSH_CLIENT$SSH_CONNECTION" ]; then
PS1+='@\[\e[1;33;44m\]\h '
else
PS1+=$__sp
fi
unset __sp
fi
PS1+='{{GIT}}'
PS1+='\[\e[1;32;44m\]'
PS1+="$P"
PS1+='\[\e[0;37;44m\]]'
PS1+='\[\e[0;1;3$(($??5:3))m\]\$\[\e[0m\] '
esac

# Add title to terminals
case "$TERM" in xterm*|rxvt*)
PS1+='\[\e]2;'
case "$(id -nu)@$SSH_CLIENT$SSH_CONNECTION" in
mina86@) PS1+='(\s)' ;;
mina86@*) PS1+='@\h' ;;
*@) PS1+='\u' ;;
*@*) PS1+='\u@\u';;
esac
PS1+=' \w\007\]'
esac
PS2=':; '

unset PROMPT_COMMAND P
export PS1 PS2



##
## Prompt GIT Stuff
##

# Sources
# * http://www.jukie.net/~bart/conf/zsh.d/S55_git
# * http://blog.madism.org/index.php/2008/05/07/173-git-prompt
# * http://github.com/jcorbin/zsh-git/
# * and of course rewritten a lot by myself

if which git >/dev/null 2>&1; then
__PS1=$PS1
__git_prompt () {
test "$PWD" = "$__GIT_PROMPT_PWD" && return 0

__GIT_PROMPT_PWD=$PWD
local dir
dir=$__GIT_PROMPT_GITDIR
if ! __GIT_PROMPT_GITDIR=$(git rev-parse --git-dir 2>/dev/null); then
PS1=${__PS1//'{{GIT}}'/}
return 0
fi

case "$__GIT_PROMPT_GITDIR" in [^/]*)
__GIT_PROMPT_GITDIR=$PWD/$__GIT_PROMPT_GITDIR
esac
test "$dir" = "$__GIT_PROMPT_GITDIR" && return 0

local branch state E ps flags _flags
state=
dir=$__GIT_PROMPT_GITDIR
if [ -d "$dir/rebase-apply" ] ; then
if [ -f "$dir/rebase-apply/rebasing" ]; then state="rb"
elif [ -f "$dir/rebase-apply/applying" ]; then state="am"
else state="am/rb"
fi
branch="$(git symbolic-ref HEAD 2>/dev/null)"
elif [ -f "$dir/rebase-merge/interactive" ]; then
state="rb-i"
branch="$(cat "$dir/rebase-merge/head-name")"
elif [ -d "$dir/rebase-merge" ]; then
state="rb-m"
branch="$(cat "$dir/rebase-merge/head-name")"
elif [ -f "$dir/MERGE_HEAD" ]; then
state="mrg"
branch="$(git symbolic-ref HEAD 2>/dev/null)"
else
[ -f "$dir/BISECT_LOG" ] && state="bisect"
branch="$(git symbolic-ref HEAD 2>/dev/null)" || \
branch="$(git describe --exact-match HEAD 2>/dev/null)" || \
branch="$(cut -c1-7 "$dir/HEAD")..."
fi
branch="${branch#refs/heads/}"
# Takes ages on big repositories
# _flags=$(git status 2>/dev/null | sed -ne '
# s/^# Untracked files:.*/u/p
# s/^# Changes to be committed:.*/i/p
# s/^# Changed but not updated:.*/m/p
# s/^# [[:space:]]*unmerged:.*/c/p')
# flags=
# case "$_flags" in *'i'*) flags+='+' ; esac
# case "$_flags" in *"c"*) flags+='!';; *"m"*) flags+='*'; esac
# case "$_flags" in *'u'*) flags+='?' ; esac

case "$flags$state" in # branch
?*) ps1="\[\e[1;32;44m\]$branch" ;;
*) ps1="\[\e[0;32;44m\]$branch"
esac
case "$state" in ?*) # (state)
ps1+="\[\e[0;37;44m\]("
ps1+="\[\e[0;32;44m\]$state"
ps1+="\[\e[0;37;44m\])"
esac
# case "$flags" in ?*) # flags
# ps1+="\[\e[1;31;44m\]$flags\[\e[0;37;44m\]"
# esac

PS1=${__PS1//'{{GIT}}'/"$ps1 "}
}

g () {
local cmds='rebase|commit|branch|checkout|cherry-pick'
cmds=$cmds"|''"$(git config --get-regexp 'alias\..*' | \
awk -F '[. ]' 'END { print cmds }
$3 ~ /'"$cmds"'/ { cmds = cmds "|" $2 }')

eval "g() {
case \"\$1\" in $cmds)
unset __GIT_PROMPT_PWD __GIT_PROMPT_GITDIR
esac
case \"\$1\" in ?*)
~/bin/g \"\$@\"
esac
}; g \"\$@\""

}

PROMPT_COMMAND='__git_prompt'
else
PS1=${PS1//'{{GIT}}'/}
fi



##
## Shell optons and parameters
##
shopt -qu cdable_vars checkhash dotglob execfail extglob interactive_comments
shopt -qu interactive_comments lithist no_empty_cmd_completion nocaseglob
shopt -qu shift_verbose sourcepath xpg_echo

shopt -qs cdspell checkwinsize cmdhist expand_aliases histappend histreedit
shopt -qs histverify hostcomplete nullglob promptvars huponexit

if [ "$_hostname" != Xdedal ]; then
shopt -qu extdebug force_fignore
shopt -qs failglob extquote gnu_errfmt
fi

# /tmp is in RAM, don't save history between reboots
export HISTFILE="/tmp/.$(id -un)-history"
HISTCONTROL="ignorespace:erasedups"
HISTIGNORE="ls:su:cd:bc:wp rm:mp3 mv:cd -"

##
## Some local stuff
##
if [ -e ~/.bash_local ]; then
. ~/.bash_local
fi
Something went wrong with that request. Please try again.