]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - shell/env
shell/env: Improve readability of LS_COLORS settings.
[config/dotfiles.git] / shell / env
1 # Configuration file for environment related options for all shells.
2
3
4 # Helper function to print debug information if $DEBUG is not empty.
5 #
6 # Doesn't fit perfectly in this file, but this is the best place to make it
7 # available everywhere.
8 source_debug() {
9     if [ x$DEBUG != x ]; then
10         echo $@
11     fi
12 }
13
14
15 source_debug "sourcing ~/.shell/env"
16
17
18 # Use UTF-8 encoding in the terminal. Don't use LC_ALL as it's used for
19 # debugging purposes. Thanks to twb in Freenode/#screen (2009-10-02 10:25).
20 LANG=en_US.UTF-8
21 export LANG
22
23 # Add ~/bin and ~/.bin to PATH if available.
24 if [ -d ~/bin ]; then
25     PATH=~/bin:$PATH
26 fi
27 if [ -d ~/.bin ]; then
28     PATH=~/.bin:$PATH
29 fi
30
31 # Use Vim as editor.
32 EDITOR=vim
33 export EDITOR
34
35 # Set less as pager, its configuration is done through the .less file.
36 PAGER=less
37 export PAGER
38
39 # Use ~/tmp as directory for temporary files if available to reduce security
40 # problems on multi-user systems.
41 if [ -O ~/tmp -a -d ~/tmp ]; then
42     TMP=~/tmp
43     TEMP=$TMP
44     TMPDIR=$TMP
45     export TMP TEMP TMPDIR
46 fi
47
48 # Set colors for GNU ls (and zsh completions).
49 # See `dircolors --print-database` for possible colors.
50 LS_COLORS='no=00'
51 LS_COLORS=$LS_COLORS':fi=00'       # normal files: normal
52 LS_COLORS=$LS_COLORS':di=34;01'    # directories: blue bold
53 LS_COLORS=$LS_COLORS':ln=36'       # symbolic links: cyan
54 LS_COLORS=$LS_COLORS':pi=00'       # named pipes: normal
55 LS_COLORS=$LS_COLORS':so=00'       # sockets: normal
56 LS_COLORS=$LS_COLORS':bd=00'       # block devices: normal
57 LS_COLORS=$LS_COLORS':cd=00'       # character devices: normal
58 LS_COLORS=$LS_COLORS':or=36;41'    # orphaned links: red background
59 LS_COLORS=$LS_COLORS':su=31;01;43' # setuid files: yellow background
60 LS_COLORS=$LS_COLORS':sg=31;01;43' # setgid files: yellow background
61 LS_COLORS=$LS_COLORS':ow=34;01;41' # directories writable by others: blue background
62 LS_COLORS=$LS_COLORS':ex=31;01'    # executables: bold red
63 export LS_COLORS
64 # Set the same colors for non GNU ls, except for orphaned links which aren't
65 # supported.
66 LSCOLORS='ExgxxxxxBxxxxxBdBdExEb'
67 #         ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
68 #         | | | | | | | | | | |
69 #         | | | | | | | | | | *- directory writable to others, without sticky bit
70 #         | | | | | | | | | *--- directory writable to others, with sticky bit
71 #         | | | | | | | | *----- executable with setgid bit set
72 #         | | | | | | | *------- executable with setuid bit set
73 #         | | | | | | *--------- character special
74 #         | | | | | *----------- block special
75 #         | | | | *------------- executable
76 #         | | | *--------------- pipe
77 #         | | *----------------- socket
78 #         | *------------------- symbolic link
79 #         *--------------------- directory
80 export LSCOLORS
81
82
83 # Sources a configuration file if it exists; loads a fallback .local file if
84 # it doesn't. If the .local files doesn't exist nothing is sourced.
85 #
86 # $1: Path to directory where configuration files are located.
87 # $2: Directory name in $1 where the non .local files are stored, can be
88 #     empty. If empty both configuration files (normal and .local) are stored
89 #     in $1.
90 # $3: Base name of file in $2, for example "rc" or "env".
91 # $4: Extension for $3, if this file doesn't exist "$1/$3.local" is sourced.
92 #     Can be empty, then no extension is used.
93 # $5: Additional options, set to nolocal to prevent loading of "$1/$3.local"
94 #                         if "$1/$2/$3.$4" doesn't exist.
95 #
96 # Example with the following directory/file structure, $os is Darwin and
97 # $hostname is marvin.
98 #
99 # ~/.zsh
100 # ~/.zsh/env
101 # ~/.zsh/env.local
102 # ~/.zsh/rc
103 # ~/.zsh/rc.local
104 # ~/.zsh/host/rc.marvin
105 # ~/.zsh/os/rc.Darwin
106 #
107 # To load additional rc files from within ~/.zsh/rc use the following:
108 #
109 # source_config ~/.zsh os   rc $os       # loads os/rc.Darwin
110 # source_config ~/.zsh host rc $hostname # loads host/rc.marvin
111 #
112 # To load additional env files from within ~/.zsh/env use the following (note
113 # nolocal to prevent loading env.local two times if os and host files don't
114 # exist):
115 #
116 # source_config zsh os   env $os       nolocal # loads os/rc.Darwin
117 # source_config zsh host env $hostname         # loads env.local
118 #
119 # By letting $4 empty normal configuration files can be sourced. A .local can
120 # still be used.
121 #
122 # source_config zsh "" file # loads zsh/file if it exists
123 #
124 # Doesn't fit perfectly in this file, but this is the best place to make it
125 # available everywhere.
126 #
127 # If DEBUG is set to a non empty value additional debug output is printed.
128 source_config() {
129     # Path to the file to source and its local counterpart.
130     if [ x$4 != x ]; then
131         source_file=$1/$2/$3.$4
132     # If $4 is empty don't append a trailing dot. This allows source_config()
133     # to load normal configuration files.
134     else
135         source_file=$1/$2/$3
136     fi
137     source_file_local=$1/$3.local
138
139     # Additional debug output.
140     source_debug "source_config(): checking if $source_file exists"
141     source_debug "source_config(): checking if $source_file_local exists"
142
143     # If the file does exist then source it.
144     if [ -f $source_file ]; then
145         source_debug "source_config(): -> sourcing $source_file"
146         . $source_file
147
148     # Otherwise load the .local file if it exists and .local files are
149     # allowed.
150     elif [ -f $source_file_local -a x$5 != xnolocal ]; then
151         source_debug "source_config(): -> sourcing $source_file_local"
152         . $source_file_local
153     else
154         source_debug "source_config(): -> neither exists"
155     fi
156
157     unset source_file source_file_local
158 }
159
160 source_debug "finished sourcing ~/.shell/env"
161
162 # vim: ft=sh