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