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