]> git.friedersdorff.com Git - max/dotfiles.git/blob - bash/.bashrc
Fix things
[max/dotfiles.git] / bash / .bashrc
1 # ~/.bashrc: executed by bash(1) for non-login shells.
2 # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
3 # for examples
4
5 # If not running interactively, don't do anything
6 case $- in
7   *i*) ;;
8   *) return;;
9 esac
10
11 # don't put duplicate lines or lines starting with space in the history.
12 # See bash(1) for more options
13 HISTCONTROL=ignoreboth
14
15 # append to the history file, don't overwrite it
16 shopt -s histappend
17
18 # for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
19 HISTSIZE=1000
20 HISTFILESIZE=2000
21
22 # check the window size after each command and, if necessary,
23 # update the values of LINES and COLUMNS.
24 shopt -s checkwinsize
25
26 # make less more friendly for non-text input files, see lesspipe(1)
27 [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
28
29 # set variable identifying the chroot you work in (used in the prompt below)
30 if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
31   debian_chroot=$(cat /etc/debian_chroot)
32 fi
33
34
35 # colored GCC warnings and errors
36 export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
37
38
39 if [ -f ~/.bash_aliases ]; then
40   . ~/.bash_aliases
41 fi
42
43 eval `dircolors ~/.dir_colors`
44
45 # enable programmable completion features (you don't need to enable
46 # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
47 # sources /etc/bash.bashrc).
48 if ! shopt -oq posix; then
49   if [ -f /usr/share/bash-completion/bash_completion ]; then
50     . /usr/share/bash-completion/bash_completion
51   elif [ -f /etc/bash_completion ]; then
52     . /etc/bash_completion
53   fi
54 fi
55
56 BLACK=$(tput setaf 0)
57 RED=$(tput setaf 1)
58 GREEN=$(tput setaf 2)
59 YELLOW=$(tput setaf 3)
60 BLUE=$(tput setaf 4)
61 MAGENTA=$(tput setaf 5)
62 CYAN=$(tput setaf 6)
63 GRAY=$(tput setaf 7)
64 BOLD=$(tput bold)
65 RESET=$(tput sgr0)
66
67 function __virtualenv_prompt() {
68   if [ -n "$VIRTUAL_ENV" ]; then
69     echo "(${VIRTUAL_ENV##*/}) "
70   fi
71 }
72
73 # set up command prompt
74 function __prompt_command()
75 {
76   # capture the exit status of the last command
77   EXIT="$?"
78   PS1=""
79
80   # check if inside git repo
81   local git_status="`git status -unormal 2>&1`"    
82   if ! [[ "$git_status" =~ Not\ a\ git\ repo ]]; then
83     # parse the porcelain output of git status
84     if [[ "$git_status" =~ nothing\ to\ commit ]]; then
85       local Color_On=$GREEN
86     elif [[ "$git_status" =~ nothing\ added\ to\ commit\ but\ untracked\ files\ present ]]; then
87       local Color_On=$CYAN
88     else
89       local Color_On=$RED
90     fi
91
92     if [[ "$git_status" =~ On\ branch\ ([^[:space:]]+) ]]; then
93       branch=${BASH_REMATCH[1]}
94     else
95       # Detached HEAD. (branch=HEAD is a faster alternative.)
96       branch="(`git describe --all --contains --abbrev=4 HEAD 2> /dev/null || echo HEAD`)"
97     fi
98
99     # add the result to prompt
100     PS1+="\n\[$Color_On\][$branch]\[$RESET\]\n"
101   fi
102
103
104   PS1+="$(__virtualenv_prompt)"
105
106   if [ $EXIT -eq 0 ]; then PS1+="\[$GREEN\][\!]\[$RESET\] "; else PS1+="\[$RED\][\!]\[$RESET\] "; fi
107
108   # if logged in via ssh shows the ip of the client
109   if [ -n "$SSH_CLIENT" ]; then 
110     IP=${SSH_CLIENT%% *}
111     PS1+="\[$YELLOW\]("$IP")\[$RESET\]"; 
112   fi
113
114   # debian chroot stuff (take it or leave it)
115   PS1+="${debian_chroot:+($debian_chroot)}"
116
117   # basic information (user@host:path)
118   PS1+="\[$RED$BOLD\]\u\[$RESET\]@\[$RED$BOLD\]\h\[$RESET\]:\[$BLUE\]\w\[$RESET\] "
119
120   
121   # prompt $ or # for root
122   PS1+="\$ "
123 }
124 PROMPT_COMMAND=__prompt_command
125
126 if ! pgrep -x -u "${USER}" gpg-agent >/dev/null 2>&1; then
127   gpg-connect-agent /bye >/dev/null 2>&1
128 fi
129
130 unset SSH_AGENT_PID
131 if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
132     export SSH_AUTH_SOCK=~/.gnupg/S.gpg-agent.ssh
133 fi
134
135 export GPG_TTY=($tty)
136 gpg-connect-agent updatestartuptty /bye > /dev/null