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