]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - shell/env
Use colorized output with normal ls when GNU ls is not available.
[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 GNU 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 # Set the same colors for non GNU ls.
24 LSCOLORS='ExgxxxxxBxxxxxBxBxExEx'
25 #         ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
26 #         | | | | | | | | | | |
27 #         | | | | | | | | | | *- directory writable to others, without sticky bit
28 #         | | | | | | | | | *--- directory writable to others, with sticky bit
29 #         | | | | | | | | *----- executable with setgid bit set
30 #         | | | | | | | *------- executable with setuid bit set
31 #         | | | | | | *--------- character special
32 #         | | | | | *----------- block special
33 #         | | | | *------------- executable
34 #         | | | *--------------- pipe
35 #         | | *----------------- socket
36 #         | *------------------- symbolic link
37 #         *--------------------- directory
38 export LSCOLORS
39
40
41 # Sources a configuration file if it exists; loads a fallback .local file if
42 # it doesn't. If the .local files doesn't exist nothing is sourced.
43 #
44 # $1: Path to directory where configuration files are located.
45 # $2: Directory name in $1 where the non .local files are stored, can be
46 #     empty. If empty both configuration files (normal and .local) are stored
47 #     in $1.
48 # $3: Base name of file in $2, for example "rc" or "env".
49 # $4: Extension for $3, if this file doesn't exist "$1/$3.local" is sourced.
50 # $5: Additional options, set to nolocal to prevent loading of "$1/$3.local"
51 #                         if "$1/$2/$3.$4" doesn't exist.
52 #
53 # Example with the following directory/file structure, $os is Darwin and
54 # $hostname is marvin.
55 #
56 # ~/.zsh
57 # ~/.zsh/env
58 # ~/.zsh/env.local
59 # ~/.zsh/rc
60 # ~/.zsh/rc.local
61 # ~/.zsh/host/rc.marvin
62 # ~/.zsh/os/rc.Darwin
63 #
64 # To load additional rc files from within ~/.zsh/rc use the following:
65 #
66 # source_config ~/.zsh os   rc $os       # loads os/rc.Darwin
67 # source_config ~/.zsh host rc $hostname # loads host/rc.marvin
68 #
69 # To load additional env files from within ~/.zsh/env use the following (note
70 # nolocal to prevent loading env.local two times if os and host files don't
71 # exist):
72 #
73 # source_config zsh os   env $os       nolocal # loads os/rc.Darwin
74 # source_config zsh host env $hostname         # loads env.local
75 #
76 # Doesn't fit perfectly in this file, but this is the best place to make it
77 # available everywhere.
78 function source_config() {
79     # Path to the file to source and its local counterpart.
80     local source_file=$1/$2/$3.$4
81     local source_file_local=$1/$3.local
82
83     # Additional debug output.
84     if [ x$DEBUG != x ]; then
85         echo "source_config(): checking if $source_file exists"
86         echo "source_config(): checking if $source_file_local exists"
87     fi
88
89     # If the file does exist then source it.
90     if [ -f $source_file ]; then
91         if [ x$DEBUG != x ]; then
92             echo "source_config(): sourcing $source_file"
93         fi
94         source $source_file
95
96     # Otherwise load the .local file if it exists and .local files are
97     # allowed.
98     elif [ -f $source_file_local -a x$5 != xnolocal ]; then
99         if [ x$DEBUG != x ]; then
100             echo "source_config(): sourcing $source_file_local"
101         fi
102         source $source_file_local
103     fi
104 }