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