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