]> arthur.barton.de Git - ConfigScripts.git/blob - sys/bashrc
8accc377173af15640adce041e596cb4b2486aca
[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                 # colors for shell prompt etc.
38                 COLOR_RESET="\[\e[0m\]"
39                 COLOR_PREPOSTTXT="\[\e[1;37m\]"
40                 COLOR_USER="\[\e[0;4m\]"
41                 COLOR_AT="\[\e[0;37m\]"
42                 COLOR_HOST="\[\e[0;4m\]"
43                 COLOR_COLON="\[\e[0;37m\]"
44                 COLOR_PATH=$reset
45                 COLOR_PROMPT_USER="\[\e[1;32m\]"
46                 COLOR_PROMPT_ROOT="\[\e[1;31m\]"
47                 COLOR_VCS="\[\e[1;33m\]"
48
49                 # colors for less(1) pager
50                 export LESS_TERMCAP_mb=$'\E[1;33m'
51                 export LESS_TERMCAP_md=$'\E[1;31m'
52                 export LESS_TERMCAP_me=$'\E[0m'
53                 export LESS_TERMCAP_se=$'\E[0m'
54                 export LESS_TERMCAP_so=$'\E[1;33;44m'
55                 export LESS_TERMCAP_ue=$'\E[0m'
56                 export LESS_TERMCAP_us=$'\E[1;32m'
57 esac
58
59 # Shell prompt
60 PS1="${COLOR_PREPOSTTXT}${PS1_BEGIN:-<}"
61 [ "$UID" -eq 0 ] \
62         || PS1="${PS1}${COLOR_USER}\u${COLOR_AT}@"
63 PS1="${PS1}${COLOR_HOST}\h"
64 PS1="${PS1}${COLOR_COLON}:"
65 PS1="${PS1}${COLOR_PATH}\w"
66 PS1="${PS1}${COLOR_PREPOSTTXT}${PS1_END:->}${COLOR_RESET} "
67 [ "$UID" -eq 0 ] \
68         && PS1="${PS1}${COLOR_PROMPT_ROOT}\\\$${COLOR_RESET} " \
69         || PS1="${PS1}${COLOR_PROMPT_USER}\\\$${COLOR_RESET} "
70 [ "\$(type -t __git_ps1)" ] \
71         && PS1="\$(__git_ps1 '(${COLOR_VCS}%s${COLOR_RESET}) ')${PS1}"
72 PS1="${chroot_name:+[${COLOR_CHROOT}$chroot_name${COLOR_RESET}] }${PS1}"
73 PS1="${COLOR_RESET}${PS1}"
74
75 # Enable bash completion, if available
76 [ -z "$BASH_COMPLETION" -a -r /etc/bash_completion ] \
77         && source /etc/bash_completion
78 [ -z "$BASH_COMPLETION" -a -r /opt/homebrew/etc/bash_completion ] \
79         && source /opt/homebrew/etc/bash_completion
80 [ -z "$BASH_COMPLETION" -a -r /opt/local/etc/bash_completion ] \
81         && source /opt/local/etc/bash_completion
82
83 # If the command-not-found package is installed, use it
84 if [ -r /etc/bash_command_not_found ]; then
85         . /etc/bash_command_not_found
86 elif [ -x /usr/lib/command-not-found ]; then
87         function command_not_found_handle {
88                 # Check because c-n-f could've been removed in the meantime
89                 if [ -x /usr/lib/command-not-found ]; then
90                         /usr/bin/python /usr/lib/command-not-found -- $1
91                         return $?
92                 else
93                         return 127
94                 fi
95         }
96 fi
97
98 # Common command aliases
99 alias ","="clear && logout"
100 alias ".."="cd .."
101 alias "ls"="ls -F"
102 alias "ll"="ls -l"
103 alias "l"="ll -a"
104 alias "lasth"="last | head -n \`expr \\\$LINES - 2\`"
105
106 # Aliases for screen(1), if installed
107 type -p screen >/dev/null 2>&1
108 if [ $? -eq 0 ]; then
109         alias "s"="screen"
110         alias "sr"="screen -dr"
111         alias "sx"="screen -x"
112 fi
113
114 # less(1) filter, if available
115 type -p lesspipe >/dev/null 2>&1 && eval `lesspipe`
116
117 # Initialize ccache(1), if installed
118 if [ -d "/usr/lib/ccache" ]; then
119         PATH="/usr/lib/ccache:$PATH"
120         # Set the cache directory to local storage, if available
121         [ -w "/usr/local/home/$USER" ] \
122                 && export CCACHE_DIR="/usr/local/home/$USER/.ccache"
123 fi
124
125 # Setup slrn(1) and cleanscore(1), if installed
126 type -p cleanscore >/dev/null 2>&1
127 [ $? -eq 0 ] && alias slrn="cleanscore -f ~/.slrnscore && slrn"
128
129 # Enable color support of ls(1) and also add handy aliases
130 if [ "$TERM" != "dumb" ]; then
131         type -p dircolors >/dev/null 2>&1 && eval `dircolors -b`
132         ls --color / >/dev/null 2>&1
133         if [ $? -eq 0 ]; then
134                 # "GNU style"
135                 alias ls="ls --color=auto -F"
136         else
137                 ls -G / >/dev/null 2>&1
138                 if [ $? -eq 0 ]; then
139                         # "BSD style"
140                         alias ls="ls -FG"
141                 fi
142         fi
143 fi
144
145 # If this is an xterm set the title to user@host:dir
146 case $TERM in
147 xterm*|rxvt|screen)
148         PROMPT_COMMAND='printf "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
149         ;;
150 *)
151         ;;
152 esac
153
154 # Source local files, if readable
155 [ -r "/etc/bashrc.local" ] && source /etc/bashrc.local
156 [ -r "/etc/bash.bashrc.local" ] && source /etc/bash.bashrc.local
157 [ -r "/var/lib/$ME/bash.bashrc" ] && source /var/lib/$ME/bash.bashrc
158
159 # -eof-