]> code.delx.au - dotfiles/blob - .bash/colors
72b72af66bf9f48b0e5de0545298cd9892852ded
[dotfiles] / .bash / colors
1 #! bash
2
3 # This file is responsible for setting up the pretty colours in GNU 'ls' and
4 # the bash prompt. It also sets COLORFGBG to give programs like vim an idea
5 # of the terminal colours to use. If your terminal isn't detected correctly
6 # then you can run lightterm or darkterm to get the colours right. To do this
7 # automatically try changing the table below.
8
9 # Terminals that we want coloured prompts in
10 [ -n "$COLORTERM" ] && PS1_COLOR=1
11 [ "$TERM" = "linux" ] && PS1_COLOR=1 && DARK=1
12 [ "$TERM" = "screen" ] && PS1_COLOR=1
13 [ "$TERM" = "xterm" ] && PS1_COLOR=1
14 [ "$TERM" = "xterm-color" ] && PS1_COLOR=1
15 [ "$TERM" = "rxvt" ] && PS1_COLOR=1
16 [ "$TERM" = "rxvt-unicode" ] && PS1_COLOR=1
17
18 # Override COLORFGBG (probably used the darkterm or lightterm function
19 if [ -n "${DARK}" ]; then
20 unset COLORFGBG
21 fi
22
23 # If COLORFGBG is set, use it to determine the terminal type, DARK=0 is
24 # dark on light, DARK=1 is light on dark.
25 if [ -n "$COLORFGBG" ]; then
26 FGCOLOR=$(echo $COLORFGBG | cut -d ';' -f 1)
27 BGCOLOR=$(echo $COLORFGBG | cut -d ';' -f 3)
28 if [ "$FGCOLOR" -gt "$BGCOLOR" ]; then
29 DARK=1
30 fi
31 unset FGCOLOR
32 unset BGCOLOR
33 else
34 # Otherwise we just do our best based on the setting of DARK, defaulting to
35 # light on dark, change the :-0 here to :-1 to change the default.
36 if [ ${DARK:-0} -eq 0 ]; then
37 export COLORFGBG="0;default;15"
38 else
39 export COLORFGBG="15;default;0"
40 fi
41 fi
42
43 # Set the prompt colour, and the colors for the 'ls' command appropriately,
44 # depending on the background of the terminal.
45 if [ ${PS1_COLOR:-0} -eq 1 ]; then
46 eval $(dircolors 2> /dev/null)
47 PS1='\[\033[00;31m\]\u@\h\[\033[00m\]:\[\033[00;34m\]\w\[\033[00m\]\$ '
48
49 if [ ${DARK:-0} -eq 0 ]; then
50 LS_COLORS="$(echo "${LS_COLORS}" | sed 's/01;/00;/g')"
51 else
52 # We need to bold the LS_COLORS and PS1 environment variables
53 # so they show up on a dark terminal
54 LS_COLORS="$(echo "${LS_COLORS}" | sed 's/00;/01;/g')"
55 PS1="$(echo "${PS1}" | sed 's/00;/01;/g')"
56 fi
57
58 export LS_COLORS
59 unset PS1_COLOR
60 unset DARK
61 fi
62