dd1a72696f162fd5285a104b5f63970deb66e8b0

Author
Marc Cornellà <marc.cornella@live.com>
Committer
GitHub <noreply@github.com>
Date

Message

core: refresh zcompdump cache file in init script (#8878)

Diff

 1diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh
 2index 30259372cd9f828a9308f3bd4a013afa85c95574..09209932544381621d4982d3ef973a47ee51f944 100644
 3--- a/oh-my-zsh.sh
 4+++ b/oh-my-zsh.sh
 5@@ -61,6 +61,18 @@ if [ -z "$ZSH_COMPDUMP" ]; then
 6   ZSH_COMPDUMP="${ZDOTDIR:-${HOME}}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
 7 fi
 8 
 9+# Construct zcompdump OMZ metadata
10+zcompdump_metadata="\
11+#omz revision: $(cd -q "$ZSH"; git rev-parse HEAD 2>/dev/null)
12+#omz fpath: $fpath\
13+"
14+
15+# Delete the zcompdump file if OMZ zcompdump metadata changed
16+if ! cmp -s <(command grep '^#omz' "$ZSH_COMPDUMP" 2>/dev/null) <<< "$zcompdump_metadata"; then
17+  command rm -f "$ZSH_COMPDUMP"
18+  zcompdump_refresh=1
19+fi
20+
21 if [[ $ZSH_DISABLE_COMPFIX != true ]]; then
22   source $ZSH/lib/compfix.zsh
23   # If completion insecurities exist, warn the user
24@@ -72,6 +84,13 @@ else
25   compinit -u -C -d "${ZSH_COMPDUMP}"
26 fi
27 
28+# Append zcompdump metadata if missing
29+if (( $zcompdump_refresh )); then
30+  echo "\n$zcompdump_metadata" >>! "$ZSH_COMPDUMP"
31+fi
32+
33+unset zcompdump_metadata zcompdump_refresh
34+
35 
36 # Load all of the config files in ~/oh-my-zsh that end in .zsh
37 # TIP: Add files you don't want in git to .gitignore