]> git.friedersdorff.com Git - max/dotfiles.git/blob - bash/.bashrc
Fix LESSOPEN environment variable
[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_status" =~ Not\ a\ git\ repo ]]; then
87     # parse the porcelain output of git status
88     if [[ "$git_status" =~ nothing\ to\ commit ]]; then
89       local Color_On=$GREEN
90     elif [[ "$git_status" =~ nothing\ added\ to\ commit\ but\ untracked\ files\ present ]]; then
91       local Color_On=$CYAN
92     else
93       local Color_On=$RED
94     fi
95
96     if [[ "$git_status" =~ On\ branch\ ([^[:space:]]+) ]]; then
97       branch=${BASH_REMATCH[1]}
98     else
99       # Detached HEAD. (branch=HEAD is a faster alternative.)
100       branch="(`git describe --all --contains --abbrev=4 HEAD 2> /dev/null || echo HEAD`)"
101     fi
102
103     # add the result to prompt
104     PS1+="\n\[$Color_On\][$branch]\[$RESET\]\n"
105   fi
106
107
108   PS1+="$(__virtualenv_prompt)"
109
110   if [ $EXIT -eq 0 ]; then PS1+="\[$GREEN\][\!]\[$RESET\] "; else PS1+="\[$RED\][\!]\[$RESET\] "; fi
111
112   # if logged in via ssh shows the ip of the client
113   if [ -n "$SSH_CLIENT" ]; then 
114     IP=${SSH_CLIENT%% *}
115     PS1+="\[$YELLOW\]("$IP")\[$RESET\]"; 
116   fi
117
118   # debian chroot stuff (take it or leave it)
119   PS1+="${debian_chroot:+($debian_chroot)}"
120
121   # basic information (user@host:path)
122   PS1+="\[$RED$BOLD\]\u\[$RESET\]@\[$RED$BOLD\]\h\[$RESET\]:\[$BLUE\]\w\[$RESET\] "
123
124   
125   # prompt $ or # for root
126   PS1+="\$ "
127 }
128 PROMPT_COMMAND=__prompt_command
129
130 if ! pgrep -x -u "${USER}" gpg-agent >/dev/null 2>&1; then
131   gpg-connect-agent /bye >/dev/null 2>&1
132 fi
133
134 unset SSH_AGENT_PID
135 if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
136     export SSH_AUTH_SOCK=~/.gnupg/S.gpg-agent.ssh
137 fi
138
139 export GPG_TTY=($tty)
140 gpg-connect-agent updatestartuptty /bye > /dev/null