.bashrc.d/20nobeep: Fallback to -blength if --blength doesn't work
[dotfiles-public.git] / src / .bashrc.d / 15prompt_dircolors
1 if test "${OS}" != gentoo
2 then
3         use_color=false
4         
5         # Set colorful PS1 only on colorful terminals.
6         # dircolors --print-database uses its own built-in database
7         # instead of using /etc/DIR_COLORS.  Try to use the external file
8         # first to take advantage of user additions.  Use internal bash
9         # globbing instead of external grep binary.
10         safe_term=${TERM//[^[:alnum:]]/?}   # sanitize TERM
11         match_lhs=""
12         [[ -f ~/.dir_colors   ]] && match_lhs="${match_lhs}$(<~/.dir_colors)"
13         [[ -f /etc/DIR_COLORS ]] && match_lhs="${match_lhs}$(</etc/DIR_COLORS)"
14         [[ -z ${match_lhs}    ]] \
15                 && type -P dircolors >/dev/null \
16                 && match_lhs=$(dircolors --print-database)
17         [[ $'\n'${match_lhs} == *$'\n'"TERM "${safe_term}* ]] && use_color=true
18         
19         if ${use_color} ; then
20                 # Enable colors for ls, etc.  Prefer ~/.dir_colors #64489
21                 if type -P dircolors >/dev/null ; then
22                         if [[ -f ~/.dir_colors ]] ; then
23                                 eval $(dircolors -b ~/.dir_colors)
24                         elif [[ -f /etc/DIR_COLORS ]] ; then
25                                 eval $(dircolors -b /etc/DIR_COLORS)
26                         fi
27                 fi
28         
29                 if [[ ${EUID} == 0 ]] ; then
30                         PS1='\[\033[01;31m\]\h\[\033[01;34m\] \W \$\[\033[00m\] '
31                 else
32                         PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\] '
33                 fi
34         else
35                 if [[ ${EUID} == 0 ]] ; then
36                         # show root@ when we don't have colors
37                         PS1='\u@\h \W \$ '
38                 else
39                         PS1='\u@\h \w \$ '
40                 fi
41         fi
42         
43         # Try to keep environment pollution down, EPA loves us.
44         unset use_color safe_term match_lhs
45 fi