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