]> code.delx.au - dotfiles/blob - .bash/colors
a3cc78e4e4071341375a261d94aff8f218dbcfe4
[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=1
17
18
19 # Terminals that we want coloured prompts in
20 [ -n "${COLORTERM}" ] && PS1_COLOR=1
21 [ "${TERM}" = "linux" ] && DARK="${DARK:-1}"
22 [ "${TERM}" = "screen.linux" ] && DARK="${DARK:-1}"
23 [ "${TERM}" = "putty" ] && DARK="${DARK:-1}"
24 [ "${TERM}" = "cygwin" ] && DARK="${DARK:-1}"
25 [ "$(tput colors)" -gt 2 ] && PS1_COLOR=1
26
27 # Override COLORFGBG (probably used the darkterm or lightterm function
28 if [ -n "${DARK}" ]; then
29 unset COLORFGBG
30 else
31 DARK="${DEFAULTDARK}"
32 fi
33 unset DEFAULTDARK
34
35 # If COLORFGBG is set, use it to determine the terminal type, DARK=0 is
36 # dark on light, DARK=1 is light on dark.
37 if [ -n "${COLORFGBG}" ]; then
38 BG="$(echo "$COLORFGBG" | sed 's/.*;//')"
39 if ! [ "${BG}" -ge 0 ]; then
40 if [ "${BG}" = "white" ]; then
41 DARK=0
42 else
43 DARK=1
44 fi
45 elif [ "${BG}" -ge 0 -a "${BG}" -le 6 -o "${BG}" -eq 8 ]; then
46 DARK=1
47 else
48 DARK=0
49 fi
50 unset BG
51 else
52 # Otherwise we just do our best based on the setting of DARK
53 if [ ${DARK} -eq 0 ]; then
54 export COLORFGBG="0;15"
55 else
56 export COLORFGBG="15;0"
57 fi
58 fi
59
60 # Set the prompt colour, and the colors for the 'ls' command appropriately,
61 # depending on the background of the terminal.
62 if [ ${PS1_COLOR:-0} -eq 1 ]; then
63 eval $(TERM=xterm dircolors 2> /dev/null)
64
65 if [ -z "$debian_chroot" -a -r /etc/debian_chroot ]; then
66 debian_chroot=$(cat /etc/debian_chroot)
67 fi
68 PS1='${debian_chroot:+($debian_chroot)}'
69 PS1="$PS1"'\[\033[00;31m\]\u@\h\[\033[00m\]:\[\033[00;34m\]\w\[\033[00m\]'
70 PS1="$PS1"'\[\033[00;36m\]$(__git_ps1 2>/dev/null)\[\033[00m\]'
71 PS1="$PS1"'\n\$ '
72
73 if [ ${DARK} -eq 0 ]; then
74 LS_COLORS="$(echo "${LS_COLORS}" | sed 's/01;/00;/g')"
75 LSCOLORS="exfxcxdxbxegedabagacad" # BSD ls
76 else
77 # We need to bold the LS_COLORS and PS1 environment variables
78 # so they show up on a dark terminal
79 LS_COLORS="$(echo "${LS_COLORS}" | sed 's/00;/01;/g')"
80 LSCOLORS="ExFxCxDxBxEGEDABAGACAD" # BSD ls
81 PS1="$(echo "${PS1}" | sed 's/00;/01;/g')"
82 fi
83
84 export LS_COLORS
85 export LSCOLORS
86 fi
87 unset PS1_COLOR
88 unset DARK
89