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