]> git.friedersdorff.com Git - max/dotfiles.git/blob - bash/.bashrc
d9e59b2c92964b995e9d22e2d1b041d7b41a2d9f
[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 if [ -x /usr/bin/lesspipe ]; then 
28   export LESSOPEN="|lesspipe %s"
29 elif [ -x /usr/bin/lesspipe.sh ]; then 
30   export LESSOPEN="|lesspipe %s"
31 fi
32
33 # set variable identifying the chroot you work in (used in the prompt below)
34 if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
35   debian_chroot=$(cat /etc/debian_chroot)
36 fi
37
38
39 # colored GCC warnings and errors
40 export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
41
42
43 if [ -f ~/.bash_aliases ]; then
44   . ~/.bash_aliases
45 fi
46
47 eval `dircolors ~/.dir_colors`
48
49 # enable programmable completion features (you don't need to enable
50 # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
51 # sources /etc/bash.bashrc).
52 if ! shopt -oq posix; then
53   if [ -f /usr/share/bash-completion/bash_completion ]; then
54     . /usr/share/bash-completion/bash_completion
55   elif [ -f /etc/bash_completion ]; then
56     . /etc/bash_completion
57   fi
58 fi
59
60 BLACK=$(tput setaf 0)
61 RED=$(tput setaf 1)
62 GREEN=$(tput setaf 2)
63 YELLOW=$(tput setaf 3)
64 BLUE=$(tput setaf 4)
65 MAGENTA=$(tput setaf 5)
66 CYAN=$(tput setaf 6)
67 GRAY=$(tput setaf 7)
68 BOLD=$(tput bold)
69 RESET=$(tput sgr0)
70
71 function __virtualenv_prompt() {
72   if [ -n "$VIRTUAL_ENV" ]; then
73     echo "(${VIRTUAL_ENV##*/}) "
74   fi
75 }
76
77 # set up command prompt
78 function __prompt_command()
79 {
80   # capture the exit status of the last command
81   EXIT="$?"
82   PS1=""
83
84   # check if inside git repo
85   local git_status="`git status -unormal 2>&1`"    
86   if git rev-parse --git-dir > /dev/null 2>&1; then
87     git_status=$(git status --porcelain)
88     # parse the porcelain output of git status
89     if [[ ! $git_status = *[![:space:]]* ]]; then
90       local Color_On=$GREEN
91     elif [[ $git_status =~ ^\?\? ]]; then
92       local Color_On=$CYAN
93     else
94       local Color_On=$RED
95     fi
96
97     branch=$(git symbolic-ref -q HEAD)
98     branch=${branch##refs/heads/}
99     branch=${branch:-HEAD}
100
101     # add the result to prompt
102     PS1+="\n\[$Color_On\][$branch]\[$RESET\]\n"
103   fi
104
105
106   PS1+="$(__virtualenv_prompt)"
107
108   if [ $EXIT -eq 0 ]; then PS1+="\[$GREEN\][\!]\[$RESET\] "; else PS1+="\[$RED\][\!]\[$RESET\] "; fi
109
110   # if logged in via ssh shows the ip of the client
111   if [ -n "$SSH_CLIENT" ]; then 
112     IP=${SSH_CLIENT%% *}
113     PS1+="\[$YELLOW\]("$IP")\[$RESET\]"; 
114   fi
115
116   # debian chroot stuff (take it or leave it)
117   PS1+="${debian_chroot:+($debian_chroot)}"
118
119   # basic information (user@host:path)
120   PS1+="\[$RED$BOLD\]\u\[$RESET\]@\[$RED$BOLD\]\h\[$RESET\]:\[$BLUE\]\w\[$RESET\]\n"
121
122   
123   # prompt $ or # for root
124   PS1+="\$ "
125 }
126 PROMPT_COMMAND=__prompt_command
127
128 if ! pgrep -x -u "${USER}" gpg-agent >/dev/null 2>&1; then
129   gpg-connect-agent /bye >/dev/null 2>&1
130 fi
131
132 unset SSH_AGENT_PID
133 if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
134   export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
135 fi
136
137 export GPG_TTY=($tty)
138 gpg-connect-agent updatestartuptty /bye > /dev/null