]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - shell/env
Improved documentation for source_config().
[config/dotfiles.git] / shell / env
1 # Configuration file for environment related options for all shells.
2
3
4 # Use UTF-8 encoding in the terminal.
5 LC_ALL=en_US.UTF-8
6 LANG=$LC_ALL
7 export LC_ALL LANG
8
9 # Use Vim as editor.
10 EDITOR=vim
11 export EDITOR
12
13 # Set less as pager, its configuration is done through the .less file.
14 PAGER=less
15 export PAGER
16
17 # Set colors for GNU ls (and zsh completions). This colors files normal (fi),
18 # directories blue bold (di), symbolic links cyan (ln), named pipes normal
19 # (pi), sockets normal (so), block devices normal (bd), character devices
20 # normal (cd), orphaned links with red background (or), setuid (su) and setgid
21 # (sg) files with yellow background, directories writable by others with blue
22 # background (ow) and executables bold red (ex).
23 # See `dircolors --print-database` for possible colors.
24 LS_COLORS="no=00:fi=00:di=34;01:ln=36:pi=00:so=00:bd=00:cd=00:\
25 or=36;41:su=31;01;43:sg=31;01;43:ow=34;01;41:ex=31;01"
26 export LS_COLORS
27 # Set the same colors for non GNU ls, except for orphaned links which aren't
28 # supported.
29 LSCOLORS='ExgxxxxxBxxxxxBdBdExEb'
30 #         ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
31 #         | | | | | | | | | | |
32 #         | | | | | | | | | | *- directory writable to others, without sticky bit
33 #         | | | | | | | | | *--- directory writable to others, with sticky bit
34 #         | | | | | | | | *----- executable with setgid bit set
35 #         | | | | | | | *------- executable with setuid bit set
36 #         | | | | | | *--------- character special
37 #         | | | | | *----------- block special
38 #         | | | | *------------- executable
39 #         | | | *--------------- pipe
40 #         | | *----------------- socket
41 #         | *------------------- symbolic link
42 #         *--------------------- directory
43 export LSCOLORS
44
45
46 # Sources a configuration file if it exists; loads a fallback .local file if
47 # it doesn't. If the .local files doesn't exist nothing is sourced.
48 #
49 # $1: Path to directory where configuration files are located.
50 # $2: Directory name in $1 where the non .local files are stored, can be
51 #     empty. If empty both configuration files (normal and .local) are stored
52 #     in $1.
53 # $3: Base name of file in $2, for example "rc" or "env".
54 # $4: Extension for $3, if this file doesn't exist "$1/$3.local" is sourced.
55 # $5: Additional options, set to nolocal to prevent loading of "$1/$3.local"
56 #                         if "$1/$2/$3.$4" doesn't exist.
57 #
58 # Example with the following directory/file structure, $os is Darwin and
59 # $hostname is marvin.
60 #
61 # ~/.zsh
62 # ~/.zsh/env
63 # ~/.zsh/env.local
64 # ~/.zsh/rc
65 # ~/.zsh/rc.local
66 # ~/.zsh/host/rc.marvin
67 # ~/.zsh/os/rc.Darwin
68 #
69 # To load additional rc files from within ~/.zsh/rc use the following:
70 #
71 # source_config ~/.zsh os   rc $os       # loads os/rc.Darwin
72 # source_config ~/.zsh host rc $hostname # loads host/rc.marvin
73 #
74 # To load additional env files from within ~/.zsh/env use the following (note
75 # nolocal to prevent loading env.local two times if os and host files don't
76 # exist):
77 #
78 # source_config zsh os   env $os       nolocal # loads os/rc.Darwin
79 # source_config zsh host env $hostname         # loads env.local
80 #
81 # Doesn't fit perfectly in this file, but this is the best place to make it
82 # available everywhere.
83 #
84 # If DEBUG is set to a non empty value additional debug output is printed.
85 function source_config() {
86     # Path to the file to source and its local counterpart.
87     local source_file=$1/$2/$3.$4
88     local source_file_local=$1/$3.local
89
90     # Additional debug output.
91     if [ x$DEBUG != x ]; then
92         echo "source_config(): checking if $source_file exists"
93         echo "source_config(): checking if $source_file_local exists"
94     fi
95
96     # If the file does exist then source it.
97     if [ -f $source_file ]; then
98         if [ x$DEBUG != x ]; then
99             echo "source_config(): sourcing $source_file"
100         fi
101         source $source_file
102
103     # Otherwise load the .local file if it exists and .local files are
104     # allowed.
105     elif [ -f $source_file_local -a x$5 != xnolocal ]; then
106         if [ x$DEBUG != x ]; then
107             echo "source_config(): sourcing $source_file_local"
108         fi
109         source $source_file_local
110     fi
111 }