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