abedafc7c8ec05bdb0f7a8a0811c0c24b9efc414
[zsh.git] / .zsh / .zshrc
1 # -*- mode: sh;-*-
2 ############
3 #
4 # .zshrc
5 # Written by Joerg Jaspert <joerg@debian.org>
6 #
7 ############
8
9 # Base directory for all plugins, themes, functions, whatever
10 ZSH=${HOME}/.zsh
11
12 if [[ ${DEBUG} != no ]]; then
13 debug () {
14 [[ "${DEBUG}" = "no" ]] && return
15 msg=${1:-""}
16 nl=${2:-""}
17 echo ${nl} "${msg}$reset_color"
18 }
19 else
20 debug () {}
21 # May want to use colors in log output...
22 autoload -U colors && colors
23 fi
24
25 debug "Starting zsh"
26
27 if zstyle -T ':ganneff:config' zrecompile; then
28 autoload -Uz zrecompile
29 zrecompile -q -p -R ${ZDOTDIR}/.zshrc -- -M ${ZDOTDIR}/var/.zcompdump
30 maybe_compile () {
31 zrecompile -q -p -U -R ${1}
32 }
33 else
34 maybe_compile () {}
35 fi
36
37 # Idea copied from https://github.com/hugues/zdotdir/blob/master/zshrc
38 # AUTHOR: Hugues Hiegel <hugues@hiegel.fr>
39 # Most of my config is splitted into files and directories
40 if [ -d ${ZDOTDIR} ]; then
41 for script in ${ZDOTDIR}/??_*.zsh; do
42 lscript=${script:t:r}
43 debug "Loading ${lscript/??_/}... " -n
44 maybe_compile ${script}
45 source $script
46 debug "$fg_no_bold[green]done"
47 for i in "net:$DOMAIN" \
48 "host:$HOST" \
49 "sys:$OSNAME" \
50 "distri:$DISTRI" \
51 "user:$USER" \
52 "user:$SUDO_USER" \
53 "net:$DOMAIN/host:$HOST" \
54 "net:$DOMAIN/sys:$OSNAME" \
55 "net:$DOMAIN/distri:$DISTRI" \
56 "net:$DOMAIN/user:$USER" \
57 "net:$DOMAIN/user:$SUDO_USER" \
58 "net:$DOMAIN/host:$HOST/sys:$OSNAME" \
59 "net:$DOMAIN/host:$HOST/distri:$DISTRI" \
60 "net:$DOMAIN/host:$HOST/user:$USER" \
61 "net:$DOMAIN/host:$HOST/user:$SUDO_USER" \
62 "net:$DOMAIN/host:$HOST/sys:$OSNAME" \
63 "net:$DOMAIN/host:$HOST/sys:$OSNAME/distri:$DISTRI" \
64 "net:$DOMAIN/host:$HOST/sys:$OSNAME/user:$USER" \
65 "net:$DOMAIN/host:$HOST/sys:$OSNAME/user:$SUDO_USER" \
66 "host:$HOST/sys:$OSNAME" \
67 "host:$HOST/distri:$DISTRI" \
68 "host:$HOST/user:$USER" \
69 "host:$HOST/user:$SUDO_USER" \
70 "host:$HOST/sys:$OSNAME/distri:$DISTRI" \
71 "host:$HOST/sys:$OSNAME/user:$USER" \
72 "host:$HOST/sys:$OSNAME/user:$SUDO_USER"
73 do
74 specific_script=${script:h}/$i/${${script:t}/??_/}
75 #debug "Checking $specific_script... "
76 if [ -r ${specific_script} ]; then
77 debug "Loading $i/${${specific_script:t:r}/??_/}... " -n
78 maybe_compile ${specific_script}
79 source ${specific_script}
80 debug "$fg_no_bold[green]done"
81 fi
82 done
83 if [[ -f ${ZDOTDIR}/${lscript}.zsh.local ]]; then
84 debug "Loading local ${lscript/??_/}... " -n
85 maybe_compile ${lscript}.zsh.local
86 source ${script}.local
87 debug "$fg_no_bold[green]done"
88 fi
89 done
90 fi
91
92 # For sudo shells
93 if [ ! -z "$SUDO_USER" ]; then
94 export HOME=~$USER
95 [ "`pwd`" = ~$SUDO_USER ] && cd
96 fi
97
98 [[ -f ${ZDOTDIR}/.zshlate ]] && source ${ZDOTDIR}/.zshlate || true
99 unfunction debug
100 unfunction maybe_compile
101
102 if zstyle -t ':ganneff:config' starttime true; then
103 end_time=$(( $(( $(date +%s) * 1000000000 )) + $(date +%N) ))
104 duration=$(( $end_time - $_start_time ))
105 echo "ZSH startup took roughly $(( $duration / 1000000.0 ))ms"
106 unset end_time; unset duration
107 fi
108 unset _start_time