Let keychain(1) inherit forwarded agents
[ConfigScripts.git] / sys / bashrc
1 #
2 # /etc/bash.bashrc: System-wide rc file for interactive bash(1) shells.
3 # Written 2003-2015 by Alexander Barton (alex@barton.de)
4 #
5
6 [ -e ~/.ConfigScripts.debug ] && echo " .. /etc/bash.bashrc ..."
7
8 BASHRCREAD="true"
9
10 [ -z "$PROFILEREAD" -a -r /etc/profile ] && source /etc/profile
11 [ -z "$PROFILEREAD" -a -r ~/.etc/profile ] && source ~/.etc/profile
12
13 [ -e ~/.ConfigScripts.debug ] && echo " >> /etc/bash.bashrc ..."
14
15 # Interactive shell?
16 case "$-" in
17         *i*) ;;
18         *) return ;;
19 esac
20
21 # Initialize keychain(1) ssh-agent and gpg-agent helper
22 [ -e ~/.ConfigScripts.debug ] && echo "     - keychain ..."
23 type -t keychain >/dev/null \
24         && eval "`keychain --agents ssh --eval --inherit any-once --quick --quiet`"
25
26 # Common command aliases (1/2)
27 alias ".."="cd .."
28 alias "ls"="ls -F"
29 alias "ll"="ls -l"
30 alias "l"="ll -a"
31
32 # Shell options (1/2)
33 set mark-directories on
34 set mark-symlinked-directories on
35 HISTCONTROL=ignoredups
36 HISTSIZE=500
37 HISTFILESIZE=2000
38
39 # Shell prompt
40 PS1="\u@\h:\w \$ "
41
42 # Make sure that the following commands are only run with bash >= 2.x
43 case "$BASH_VERSION" in
44         "0."*|"1."*) return; ;;
45         *)
46 esac
47
48 # Shell options (2/2)
49 [ -e ~/.ConfigScripts.debug ] && echo "     - shell options ..."
50 shopt -s checkwinsize
51 shopt -s cdspell
52 shopt -s histappend
53 shopt -s histreedit
54 shopt -s histverify
55
56 # Shell functions
57 sshnew() {
58         ssh -o "StrictHostKeyChecking no" "$@"
59 }
60 sshtmp() {
61         ssh -o "StrictHostKeyChecking no" -o "UserKnownHostsFile /dev/null" "$@"
62 }
63
64 # Map up & down to history search once a command has been started
65 bind '"\e[A":history-search-backward'
66 bind '"\e[B":history-search-forward'
67
68 # Colors
69 [ -e ~/.ConfigScripts.debug ] && echo "     - colors ..."
70 case "$TERM" in
71         ansi|cons25|cygwin|dtterm|linux|rxvt|screen*|vt100|vt200|vt220|vt320| \
72         xterm|xterm-color|xterm-256color)
73                 # color terminal
74
75                 # terminal attributes
76                 #   0: reset / 1: bright / 2: dim / 4: underline / 5: blink /
77                 #   7: reverse / 8: hidden.
78                 # foreground colors
79                 #   30: black / 31: red / 32: green / 33: yellow / 34: blue /
80                 #   35: magenta / 36: cyan / 37: white
81                 # background colors
82                 #   40: black / 41: red / 42: green / 43: yellow / 44: blue /
83                 #   45: magenta / 46: cyan / 47: white
84
85                 # colors for shell prompt etc.
86                 COLOR_RESET="\[\e[0m\]"
87                 COLOR_PREPOSTTXT="\[\e[1;37m\]"
88                 COLOR_USER="\[\e[0;4m\]"
89                 COLOR_AT="\[\e[0;37m\]"
90                 COLOR_HOST="\[\e[0;4m\]"
91                 COLOR_COLON="\[\e[0;37m\]"
92                 COLOR_PATH=$reset
93                 COLOR_PROMPT_USER="\[\e[1;32m\]"
94                 COLOR_PROMPT_ROOT="\[\e[1;31m\]"
95                 COLOR_VCS="\[\e[1;33m\]"
96                 COLOR_HISTORY=$reset
97
98                 # colors for less(1) pager
99                 export LESS_TERMCAP_mb=$'\E[1;33m'
100                 export LESS_TERMCAP_md=$'\E[1;31m'
101                 export LESS_TERMCAP_me=$'\E[0m'
102                 export LESS_TERMCAP_se=$'\E[0m'
103                 export LESS_TERMCAP_so=$'\E[1;33;44m'
104                 export LESS_TERMCAP_ue=$'\E[0m'
105                 export LESS_TERMCAP_us=$'\E[1;32m'
106 esac
107
108 # Enable bash completion, if available
109 if ! shopt -oq posix; then
110         [ -e ~/.ConfigScripts.debug ] && echo "     - bash completion ..."
111         [ -z "$BASH_COMPLETION" -a -r /etc/bash_completion ] \
112                 && source /etc/bash_completion
113         [ -z "$BASH_COMPLETION" -a -r /usr/local/etc/bash_completion ] \
114                 && source /usr/local/etc/bash_completion
115         [ -z "$BASH_COMPLETION" -a -r /opt/homebrew/etc/bash_completion ] \
116                 && source /opt/homebrew/etc/bash_completion
117         [ -z "$BASH_COMPLETION" -a -r /opt/local/etc/bash_completion ] \
118                 && source /opt/local/etc/bash_completion
119 fi
120
121 # Enable local virtualenvwrapper installation, if available
122 [ -e ~/.ConfigScripts.debug ] && echo "     - virtualenvwrapper ..."
123 [ -r /usr/local/bin/virtualenvwrapper.sh ] \
124         && source /usr/local/bin/virtualenvwrapper.sh
125
126 # Shell prompt
127 [ -e ~/.ConfigScripts.debug ] && echo "     - prompt ..."
128 PS1="${COLOR_PREPOSTTXT}${PS1_BEGIN:-<}"
129 [ "$LOGNAME" = "root" ] \
130         || PS1="${PS1}${COLOR_USER}\u${COLOR_AT}@"
131 PS1="${PS1}${COLOR_HOST}\h"
132 PS1="${PS1}${COLOR_COLON}:"
133 PS1="${PS1}${COLOR_PATH}\W "
134 PS1="${PS1}${COLOR_HISTORY}\!"
135 PS1="${PS1}${COLOR_PREPOSTTXT}${PS1_END:->}${COLOR_RESET} "
136 [ "$LOGNAME" = "root" ] \
137         && PS1="${PS1}${COLOR_PROMPT_ROOT}\\\$${COLOR_RESET} " \
138         || PS1="${PS1}${COLOR_PROMPT_USER}\\\$${COLOR_RESET} "
139 type -t __git_ps1 >/dev/null \
140         && PS1="\$(__git_ps1 '(${COLOR_VCS}%s${COLOR_RESET}) ')${PS1}"
141 PS1="${chroot_name:+[${COLOR_CHROOT}$chroot_name${COLOR_RESET}] }${PS1}"
142 PS1="${COLOR_RESET}${PS1}"
143
144 # If the command-not-found package is installed, use it
145 [ -e ~/.ConfigScripts.debug ] && echo "     - command_not_found ..."
146 if [ -r /etc/bash_command_not_found ]; then
147         . /etc/bash_command_not_found
148 elif [ -x /usr/lib/command-not-found ]; then
149         function command_not_found_handle {
150                 # Check because c-n-f could've been removed in the meantime
151                 if [ -x /usr/lib/command-not-found ]; then
152                         /usr/bin/python /usr/lib/command-not-found -- $1
153                         return $?
154                 else
155                         return 127
156                 fi
157         }
158 fi
159
160 # Common command aliases (2/2)
161 [ -e ~/.ConfigScripts.debug ] && echo "     - aliases ..."
162 alias "lasth"="last | head -n \`expr \\\$LINES - 2\`"
163 alias "lastf"="last | grep -v \"^\$LOGNAME\""
164
165 # Aliases for screen(1), if installed
166 type -t screen >/dev/null
167 if [ $? -eq 0 ]; then
168         alias "s"="screen"
169         alias "sr"="screen -dr"
170         alias "sx"="screen -x"
171 fi
172
173 # less(1) filter, if available
174 type -t lesspipe >/dev/null \
175         && eval `lesspipe`
176
177 # Setup slrn(1) and cleanscore(1), if installed
178 type -t cleanscore >/dev/null \
179         && alias slrn="cleanscore -f ~/.slrnscore && slrn"
180
181 # Enable color support of ls(1)
182 if [ "$TERM" != "dumb" ]; then
183         type -t dircolors >/dev/null && eval `dircolors -b`
184         ls --color / >/dev/null 2>&1
185         if [ $? -eq 0 ]; then
186                 # "GNU style"
187                 alias ls="ls --color=auto -F"
188         else
189                 ls -G / >/dev/null 2>&1
190                 if [ $? -eq 0 ]; then
191                         # "BSD style"
192                         alias ls="ls -FG"
193                 fi
194         fi
195 fi
196
197 # If this is an xterm set the title to user@host:dir
198 [ -e ~/.ConfigScripts.debug ] && echo "     - prompt command ..."
199 case $TERM in
200 xterm*|rxvt|screen)
201         PROMPT_COMMAND='printf "\033]0;${LOGNAME}@${HOSTNAME}: ${PWD}\007"'
202         ;;
203 *)
204         ;;
205 esac
206
207 # Source local files, if readable
208 [ -r "/etc/bashrc.local" ] && source /etc/bashrc.local
209 [ -r "/etc/bash.bashrc.local" ] && source /etc/bash.bashrc.local
210 [ -r "/var/lib/$HOSTNAME/bash.bashrc" ] && source /var/lib/$HOSTNAME/bash.bashrc
211
212 # -eof-