]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - shell/env
Simplified loading of config files by using a function.
[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 export LC_ALL
7
8 # Use Vim as editor.
9 EDITOR=vim
10 export EDITOR
11
12 # Set less as pager, its configuration is done through the .less file.
13 PAGER=less
14 export PAGER
15
16 # Set colors for ls (and zsh completions). This colors files normal (fi),
17 # directories blue bold (di), symbolic links cyan (ln), named pipes normal
18 # (pi), sockets normal (so), block devices normal (bd), character devices
19 # normal (cd) and executables bold red (ex).
20 # See `dircolors --print-database` for possible colors.
21 LS_COLORS='no=00:fi=00:di=34;01:ln=36:pi=00:so=00:bd=00:cd=00:ex=31;01'
22 export LS_COLORS
23
24
25 # Sources a configuration file if it exists; loads a fallback .local file if
26 # it doesn't. If the .local files doesn't exist nothing is sourced.
27 #
28 # $1: Path to directory where configuration files are located.
29 # $2: Directory name in $1 where the non .local files are stored, can be
30 #     empty. If empty both configuration files (normal and .local) are stored
31 #     in $1.
32 # $3: Base name of file in $2, for example "rc" or "env".
33 # $4: Extension for $3, if this file doesn't exist "$1/$3.local" is sourced.
34 # $5: Additional options, set to nolocal to prevent loading of "$1/$3.local"
35 #                         if "$1/$2/$3.$4" doesn't exist.
36 #
37 # Example with the following directory/file structure, $os is Darwin and
38 # $hostname is marvin.
39 #
40 # ~/.zsh
41 # ~/.zsh/env
42 # ~/.zsh/env.local
43 # ~/.zsh/rc
44 # ~/.zsh/rc.local
45 # ~/.zsh/host/rc.marvin
46 # ~/.zsh/os/rc.Darwin
47 #
48 # To load additional rc files from within ~/.zsh/rc use the following:
49 #
50 # source_config ~/.zsh os   rc $os       # loads os/rc.Darwin
51 # source_config ~/.zsh host rc $hostname # loads host/rc.marvin
52 #
53 # To load additional env files from within ~/.zsh/env use the following (note
54 # nolocal to prevent loading env.local two times if os and host files don't
55 # exist):
56 #
57 # source_config zsh os   env $os       nolocal # loads os/rc.Darwin
58 # source_config zsh host env $hostname         # loads env.local
59 #
60 # Doesn't fit perfectly in this file, but this is the best place to make it
61 # available everywhere.
62 function source_config() {
63     # Path to the file to source and its local counterpart.
64     local source_file=$1/$2/$3.$4
65     local source_file_local=$1/$3.local
66
67     # Additional debug output.
68     if [ x$DEBUG != x ]; then
69         echo "source_config(): checking if $source_file exists"
70         echo "source_config(): checking if $source_file_local exists"
71     fi
72
73     # If the file does exist then source it.
74     if [ -f $source_file ]; then
75         if [ x$DEBUG != x ]; then
76             echo "source_config(): sourcing $source_file"
77         fi
78         source $source_file
79
80     # Otherwise load the .local file if it exists and .local files are
81     # allowed.
82     elif [ -f $source_file_local -a x$5 != xnolocal ]; then
83         if [ x$DEBUG != x ]; then
84             echo "source_config(): sourcing $source_file_local"
85         fi
86         source $source_file_local
87     fi
88 }