]> code.delx.au - dotfiles/blob - .bash/colors
Reworked bash init scripts.
[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 # Use colours appropriate to a light on dark terminal, we can autodetect
19 # this for some terminals, for others we define it above.
20 if [ -n "$COLORFGBG" ]; then
21 FGCOLOR=$(echo $COLORFGBG | cut -d ';' -f 1)
22 BGCOLOR=$(echo $COLORFGBG | cut -d ';' -f 3)
23 if [ "$FGCOLOR" -gt "$BGCOLOR" ]; then
24 DARK=1
25 fi
26 unset FGCOLOR
27 unset BGCOLOR
28 elif [ ${DARK:-0} -eq 0 ]; then
29 export COLORFGBG="0;default;15"
30 elif [ ${DARK:-0} -eq 1 ]; then
31 export COLORFGBG="15;default;0"
32 fi
33
34 # Set the prompt colour, and the colors for the 'ls' command appropriately,
35 # depending on the background of the terminal.
36 if [ ${PS1_COLOR:-0} -eq 1 ]; then
37 LS_COLORS='no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:do=00;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:tw=30;42:ow=34;42:st=37;44:ex=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.deb=00;31:*.rpm=00;31:*.jar=00;31:*.jpg=00;35:*.jpeg=00;35:*.gif=00;35:*.bmp=00;35:*.pbm=00;35:*.pgm=00;35:*.ppm=00;35:*.tga=00;35:*.xbm=00;35:*.xpm=00;35:*.tif=00;35:*.tiff=00;35:*.png=00;35:*.mov=00;35:*.mpg=00;35:*.mpeg=00;35:*.avi=00;35:*.fli=00;35:*.gl=00;35:*.dl=00;35:*.xcf=00;35:*.xwd=00;35:*.flac=00;35:*.mp3=00;35:*.mpc=00;35:*.ogg=00;35:*.wav=00;35:'
38 PS1='\[\033[00;31m\]\u@\h\[\033[00m\]:\[\033[00;34m\]\w\[\033[00m\]\$ '
39
40 if [ ${DARK:-0} -eq 1 ]; then
41 # We need to bold the LS_COLORS and PS1 environment variables
42 # so they show up on a dark terminal
43 LS_COLORS="$(echo "${LS_COLORS}" | sed 's/00;/01;/g')"
44 PS1="$(echo "${PS1}" | sed 's/00;/01;/g')"
45 fi
46
47 export LS_COLORS
48 unset PS1_COLOR
49 unset DARK
50 fi
51