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