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