]> code.delx.au - dotfiles/blob - .bash/colors
Fixed screen magic to be better
[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. Depending on whether you use a light on dark, or dark on
5 # light terminal you want different colour schemes. Rxvt and some other
6 # set the COLORFGBG environment variable to make autodetecting this easy.
7
8 # These scripts attempt to detect the terminal colours, and then set COLORFGBG
9 # if it isn't already set so that programs like vim can set the correct colours.
10
11 # If your terminal isn't detected correctly then you can run lightterm or
12 # darkterm to get the colours right. The default can be adjusted below.
13
14 # Set to 0 for light background terminal colours by default
15 # Set to 1 for dark background terminal colours by default
16 DEFAULTDARK=0
17
18
19 # Terminals that we want coloured prompts in
20 [ -n "${COLORTERM}" ] && PS1_COLOR=1
21 [ "${TERM}" = "linux" ] && PS1_COLOR=1 && DARK=1
22 [ "${TERM}" = "screen" ] && PS1_COLOR=1
23 [ "${TERM}" = "xterm" ] && PS1_COLOR=1
24 [ "${TERM}" = "xterm-color" ] && PS1_COLOR=1
25 [ "${TERM}" = "rxvt" ] && PS1_COLOR=1
26 [ "${TERM}" = "rxvt-unicode" ] && PS1_COLOR=1
27
28 # Override COLORFGBG (probably used the darkterm or lightterm function
29 if [ -n "${DARK}" ]; then
30 unset COLORFGBG
31 else
32 DARK="${DEFAULTDARK}"
33 fi
34 unset DEFAULTDARK
35
36 # If COLORFGBG is set, use it to determine the terminal type, DARK=0 is
37 # dark on light, DARK=1 is light on dark.
38 if [ -n "${COLORFGBG}" ]; then
39 FGBG="$(echo $COLORFGBG | sed 's/;.*;/;/')" # Allow for rxvt without xpm
40 FG=$(echo "${FGBG}" | cut -d ';' -f 1)
41 BG=$(echo "${FGBG}" | cut -d ';' -f 2)
42 if [ "${FG}" = "white" -o "${FG}" = "green" ]; then
43 DARK=1
44 elif [ "${BG}" = "black" ]; then
45 DARK=1
46 elif [ "${FG}" = "black" ]; then
47 DARK=0
48 elif [ "${BG}" = "white" ]; then
49 DARK=0
50 elif [ "${FG}" -gt "${BG}" ]; then
51 DARK=1
52 elif [ "${FG}" -lt "${BG}" ]; then
53 DARK=0
54 fi
55 unset FG
56 unset BG
57 unset FGBG
58 else
59 # Otherwise we just do our best based on the setting of DARK
60 if [ ${DARK} -eq 0 ]; then
61 export COLORFGBG="0;15"
62 else
63 export COLORFGBG="15;0"
64 fi
65 fi
66
67 # Set the prompt colour, and the colors for the 'ls' command appropriately,
68 # depending on the background of the terminal.
69 if [ ${PS1_COLOR:-0} -eq 1 ]; then
70 eval $(dircolors 2> /dev/null)
71 PS1='\[\033[00;31m\]\u@\h\[\033[00m\]:\[\033[00;34m\]\w\[\033[00m\]\$ '
72
73 if [ ${DARK} -eq 0 ]; then
74 LS_COLORS="$(echo "${LS_COLORS}" | sed 's/01;/00;/g')"
75 else
76 # We need to bold the LS_COLORS and PS1 environment variables
77 # so they show up on a dark terminal
78 LS_COLORS="$(echo "${LS_COLORS}" | sed 's/00;/01;/g')"
79 PS1="$(echo "${PS1}" | sed 's/00;/01;/g')"
80 fi
81
82 export LS_COLORS
83 fi
84 unset PS1_COLOR
85 unset DARK
86