]> git.friedersdorff.com Git - max/dotfiles.git/blob - bash/.bashrc
Merge branch 'master' of git.friedersdorff.com:max/dotfiles
[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 # don't put duplicate lines or lines starting with space in the history.
6 # See bash(1) for more options
7 HISTCONTROL=ignoreboth
8
9 # append to the history file, don't overwrite it
10 shopt -s histappend
11
12 # for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
13 HISTSIZE=1000
14 HISTFILESIZE=20000
15
16 # check the window size after each command and, if necessary,
17 # update the values of LINES and COLUMNS.
18 shopt -s checkwinsize
19
20 if [ -f ~/.bash_aliases ]; then
21   . ~/.bash_aliases
22 fi
23
24
25 # enable programmable completion features (you don't need to enable
26 # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
27 # sources /etc/bash.bashrc).
28 if ! shopt -oq posix; then
29   if [ -f /usr/share/bash-completion/bash_completion ]; then
30     . /usr/share/bash-completion/bash_completion
31   elif [ -f /etc/bash_completion ]; then
32     . /etc/bash_completion
33   fi
34 fi
35
36 BLACK=$(tput setaf 0)
37 RED=$(tput setaf 1)
38 GREEN=$(tput setaf 2)
39 YELLOW=$(tput setaf 3)
40 BLUE=$(tput setaf 4)
41 MAGENTA=$(tput setaf 5)
42 CYAN=$(tput setaf 6)
43 GRAY=$(tput setaf 7)
44 BOLD=$(tput bold)
45 RESET=$(tput sgr0)
46
47 function __virtualenv_prompt() {
48   if [ -n "$VIRTUAL_ENV" ]; then
49     echo "(${VIRTUAL_ENV##*/}) "
50   fi
51 }
52
53 # set up command prompt
54 function __prompt_command()
55 {
56   # capture the exit status of the last command
57   EXIT="$?"
58   PS1=""
59
60   # check if inside git repo
61   local git_status="`git status -unormal 2>&1`"    
62   if git rev-parse --git-dir > /dev/null 2>&1; then
63     git_status=$(git status --porcelain)
64     # parse the porcelain output of git status
65     if [[ ! $git_status = *[![:space:]]* ]]; then
66       local Color_On=$GREEN
67     elif [[ $git_status =~ ^\?\? ]]; then
68       local Color_On=$CYAN
69     else
70       local Color_On=$RED
71     fi
72
73     branch=$(git symbolic-ref -q HEAD)
74     branch=${branch##refs/heads/}
75     branch=${branch:-HEAD}
76
77     # add the result to prompt
78     PS1+="\n\[$Color_On\][$branch]\[$RESET\]\n"
79   fi
80
81
82   PS1+="$(__virtualenv_prompt)"
83
84   if [ $EXIT -eq 0 ]; then PS1+="\[$GREEN\][\!]\[$RESET\] "; else PS1+="\[$RED\][\!]\[$RESET\] "; fi
85
86   # if logged in via ssh shows the ip of the client
87   if [ -n "$SSH_CLIENT" ]; then 
88     IP=${SSH_CLIENT%% *}
89     PS1+="\[$YELLOW\]("$IP")\[$RESET\]"; 
90   fi
91
92   # debian chroot stuff (take it or leave it)
93   PS1+="${debian_chroot:+($debian_chroot)}"
94
95   # basic information (user@host:path)
96   PS1+="\[$RED$BOLD\]\u\[$RESET\]@\[$RED$BOLD\]\h\[$RESET\]:\[$BLUE\]\w\[$RESET\]\n"
97
98   
99   # prompt $ or # for root
100   PS1+="\$ "
101 }
102 PROMPT_COMMAND=__prompt_command
103
104 if ! pgrep -x -u "${USER}" gpg-agent >/dev/null 2>&1; then
105   gpg-connect-agent /bye >/dev/null 2>&1
106 fi
107
108 unset SSH_AGENT_PID
109 if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
110   export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
111 fi
112
113 export GPG_TTY=($tty)
114 gpg-connect-agent updatestartuptty /bye > /dev/null
115
116 export EDITOR="vim"
117 export TMPDIR="/home/max/.local/tmp"
118 eval `dircolors ~/.dir_colors`