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