]> arthur.barton.de Git - ConfigScripts.git/blob - sys/bashrc
Set color-related variables if a color-capable terminal is detected
[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 [ "$UID" -eq 0 ] \
61         && PS1="\h:\w \\\$ " \
62         || PS1="\u@\h:\w \\\$ "
63 if [ "\$(type -t __git_ps1)" ]; then
64         PS1="\$(__git_ps1 '(%s) ')$PS1"
65 fi
66 PS1="${chroot_name:+[$chroot_name] }$PS1"
67
68 # Enable bash completion, if available
69 [ -z "$BASH_COMPLETION" -a -r /etc/bash_completion ] \
70         && source /etc/bash_completion
71 [ -z "$BASH_COMPLETION" -a -r /opt/homebrew/etc/bash_completion ] \
72         && source /opt/homebrew/etc/bash_completion
73 [ -z "$BASH_COMPLETION" -a -r /opt/local/etc/bash_completion ] \
74         && source /opt/local/etc/bash_completion
75
76 # If the command-not-found package is installed, use it
77 if [ -r /etc/bash_command_not_found ]; then
78         . /etc/bash_command_not_found
79 elif [ -x /usr/lib/command-not-found ]; then
80         function command_not_found_handle {
81                 # Check because c-n-f could've been removed in the meantime
82                 if [ -x /usr/lib/command-not-found ]; then
83                         /usr/bin/python /usr/lib/command-not-found -- $1
84                         return $?
85                 else
86                         return 127
87                 fi
88         }
89 fi
90
91 # Common command aliases
92 alias ","="clear && logout"
93 alias ".."="cd .."
94 alias "ls"="ls -F"
95 alias "ll"="ls -l"
96 alias "l"="ll -a"
97 alias "lasth"="last | head -n \`expr \\\$LINES - 2\`"
98
99 # Aliases for screen(1), if installed
100 type -p screen >/dev/null 2>&1
101 if [ $? -eq 0 ]; then
102         alias "s"="screen"
103         alias "sr"="screen -dr"
104         alias "sx"="screen -x"
105 fi
106
107 # less(1) filter, if available
108 type -p lesspipe >/dev/null 2>&1 && eval `lesspipe`
109
110 # Initialize ccache(1), if installed
111 if [ -d "/usr/lib/ccache" ]; then
112         PATH="/usr/lib/ccache:$PATH"
113         # Set the cache directory to local storage, if available
114         [ -w "/usr/local/home/$USER" ] \
115                 && export CCACHE_DIR="/usr/local/home/$USER/.ccache"
116 fi
117
118 # Setup slrn(1) and cleanscore(1), if installed
119 type -p cleanscore >/dev/null 2>&1
120 [ $? -eq 0 ] && alias slrn="cleanscore -f ~/.slrnscore && slrn"
121
122 # Enable color support of ls(1) and also add handy aliases
123 if [ "$TERM" != "dumb" ]; then
124         type -p dircolors >/dev/null 2>&1 && eval `dircolors -b`
125         ls --color / >/dev/null 2>&1
126         if [ $? -eq 0 ]; then
127                 # "GNU style"
128                 alias ls="ls --color=auto -F"
129         else
130                 ls -G / >/dev/null 2>&1
131                 if [ $? -eq 0 ]; then
132                         # "BSD style"
133                         alias ls="ls -FG"
134                 fi
135         fi
136 fi
137
138 # If this is an xterm set the title to user@host:dir
139 case $TERM in
140 xterm*|rxvt|screen)
141         PROMPT_COMMAND='printf "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
142         ;;
143 *)
144         ;;
145 esac
146
147 # Source local files, if readable
148 [ -r "/etc/bashrc.local" ] && source /etc/bashrc.local
149 [ -r "/etc/bash.bashrc.local" ] && source /etc/bash.bashrc.local
150 [ -r "/var/lib/$ME/bash.bashrc" ] && source /var/lib/$ME/bash.bashrc
151
152 # -eof-