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.
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.
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.
14 # Set to 0 for light background terminal colours by default
15 # Set to 1 for dark background terminal colours by default
19 # Terminals that we want coloured prompts in
20 [ -n "${COLORTERM}" ] && PS1_COLOR=1
21 [ "${TERM}" = "linux" ] && DARK="${DARK:-1}"
22 [ "$(tput colors)" -gt 2 ] && PS1_COLOR=1
24 # Override COLORFGBG (probably used the darkterm or lightterm function
25 if [ -n "${DARK}" ]; then
32 # If COLORFGBG is set, use it to determine the terminal type, DARK=0 is
33 # dark on light, DARK=1 is light on dark.
34 if [ -n "${COLORFGBG}" ]; then
35 FGBG="$(echo $COLORFGBG | sed 's/;.*;/;/')" # Allow for rxvt without xpm
36 FG=$(echo "${FGBG}" | cut -d ';' -f 1)
37 BG=$(echo "${FGBG}" | cut -d ';' -f 2)
38 if [ "${FG}" = "white" -o "${FG}" = "green" ]; then
40 elif [ "${BG}" = "black" ]; then
42 elif [ "${FG}" = "black" ]; then
44 elif [ "${BG}" = "white" ]; then
46 elif [ "${FG}" -gt "${BG}" ]; then
48 elif [ "${FG}" -lt "${BG}" ]; then
55 # Otherwise we just do our best based on the setting of DARK
56 if [ ${DARK} -eq 0 ]; then
57 export COLORFGBG="0;15"
59 export COLORFGBG="15;0"
63 # Set the prompt colour, and the colors for the 'ls' command appropriately,
64 # depending on the background of the terminal.
65 if [ ${PS1_COLOR:-0} -eq 1 ]; then
66 eval $(dircolors 2> /dev/null)
67 PS1='\[\033[00;31m\]\u@\h\[\033[00m\]:\[\033[00;34m\]\w\[\033[00m\]\$ '
69 if [ ${DARK} -eq 0 ]; then
70 LS_COLORS="$(echo "${LS_COLORS}" | sed 's/01;/00;/g')"
72 # We need to bold the LS_COLORS and PS1 environment variables
73 # so they show up on a dark terminal
74 LS_COLORS="$(echo "${LS_COLORS}" | sed 's/00;/01;/g')"
75 PS1="$(echo "${PS1}" | sed 's/00;/01;/g')"