oh-my-zsh.sh 3.8 KB
Newer Older
1
2
3
4
5
6
# Set ZSH_CACHE_DIR to the path where cache files should be created
# or else we will use the default cache/
if [[ -z "$ZSH_CACHE_DIR" ]]; then
  ZSH_CACHE_DIR="$ZSH/cache"
fi

7
# Check for updates on initial load...
8
9
10
if [ "$DISABLE_AUTO_UPDATE" != "true" ]; then
  source $ZSH/tools/check_for_upgrade.sh
fi
11

12
13
# Initializes Oh My Zsh

14
# add a function path
Guten's avatar
Guten committed
15
fpath=($ZSH/functions $ZSH/completions $fpath)
16

17
18
19
# Load all stock functions (from $fpath files) called below.
autoload -U compaudit compinit

20
21
22
23
24
25
# Set ZSH_CUSTOM to the path where your custom config files
# and plugins exists, or else we will use the default custom/
if [[ -z "$ZSH_CUSTOM" ]]; then
    ZSH_CUSTOM="$ZSH/custom"
fi

Stephen's avatar
Stephen committed
26

27
28
29
is_plugin() {
  local base_dir=$1
  local name=$2
30
31
  builtin test -f $base_dir/plugins/$name/$name.plugin.zsh \
    || builtin test -f $base_dir/plugins/$name/_$name
32
}
33

34
35
36
# Add all defined plugins to fpath. This must be done
# before running compinit.
for plugin ($plugins); do
37
  if is_plugin $ZSH_CUSTOM $plugin; then
38
    fpath=($ZSH_CUSTOM/plugins/$plugin $fpath)
39
  elif is_plugin $ZSH $plugin; then
40
    fpath=($ZSH/plugins/$plugin $fpath)
41
  else
42
    echo "[oh-my-zsh] plugin '$plugin' not found"
43
44
  fi
done
45

46
# Figure out the SHORT hostname
47
if [[ "$OSTYPE" = darwin* ]]; then
48
  # macOS's $HOST changes with dhcp, etc. Use ComputerName if possible.
49
  SHORT_HOST=$(scutil --get ComputerName 2>/dev/null) || SHORT_HOST=${HOST/.*/}
50
51
52
53
54
else
  SHORT_HOST=${HOST/.*/}
fi

# Save the location of the current completion dump file.
55
56
57
if [ -z "$ZSH_COMPDUMP" ]; then
  ZSH_COMPDUMP="${ZDOTDIR:-${HOME}}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
fi
58

59
# Construct zcompdump OMZ metadata
60
61
zcompdump_revision="#omz revision: $(builtin cd -q "$ZSH"; git rev-parse HEAD 2>/dev/null)"
zcompdump_fpath="#omz fpath: $fpath"
62
63

# Delete the zcompdump file if OMZ zcompdump metadata changed
64
65
if ! command grep -q -Fx "$zcompdump_revision" "$ZSH_COMPDUMP" 2>/dev/null \
   || ! command grep -q -Fx "$zcompdump_fpath" "$ZSH_COMPDUMP" 2>/dev/null; then
66
67
68
69
  command rm -f "$ZSH_COMPDUMP"
  zcompdump_refresh=1
fi

70
if [[ $ZSH_DISABLE_COMPFIX != true ]]; then
71
  source $ZSH/lib/compfix.zsh
72
  # If completion insecurities exist, warn the user
73
  handle_completion_insecurities
74
  # Load only from secure directories
75
  compinit -i -C -d "${ZSH_COMPDUMP}"
76
else
77
  # If the user wants it, load from all found directories
78
  compinit -u -C -d "${ZSH_COMPDUMP}"
79
fi
80

81
82
# Append zcompdump metadata if missing
if (( $zcompdump_refresh )); then
83
84
85
  # Use `tee` in case the $ZSH_COMPDUMP filename is invalid, to silence the error
  # See https://github.com/ohmyzsh/ohmyzsh/commit/dd1a7269#commitcomment-39003489
  tee -a "$ZSH_COMPDUMP" &>/dev/null <<EOF
86
87
88
89

$zcompdump_revision
$zcompdump_fpath
EOF
90
91
fi

92
unset zcompdump_revision zcompdump_fpath zcompdump_refresh
93

94
95
96
97
98
99
100
101
102

# Load all of the config files in ~/oh-my-zsh that end in .zsh
# TIP: Add files you don't want in git to .gitignore
for config_file ($ZSH/lib/*.zsh); do
  custom_config_file="${ZSH_CUSTOM}/lib/${config_file:t}"
  [ -f "${custom_config_file}" ] && config_file=${custom_config_file}
  source $config_file
done

103
# Load all of the plugins that were defined in ~/.zshrc
Pat Regan's avatar
Pat Regan committed
104
for plugin ($plugins); do
105
106
  if [ -f $ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh ]; then
    source $ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh
107
  elif [ -f $ZSH/plugins/$plugin/$plugin.plugin.zsh ]; then
108
109
110
111
    source $ZSH/plugins/$plugin/$plugin.plugin.zsh
  fi
done

112
113
114
115
116
117
# Load all of your custom configurations from custom/
for config_file ($ZSH_CUSTOM/*.zsh(N)); do
  source $config_file
done
unset config_file

118
# Load the theme
119
120
121
122
123
if [ ! "$ZSH_THEME" = ""  ]; then
  if [ -f "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme" ]; then
    source "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme"
  elif [ -f "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme" ]; then
    source "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme"
124
  else
125
    source "$ZSH/themes/$ZSH_THEME.zsh-theme"
126
  fi
127
fi