about summary refs log tree commit diff
path: root/Completion/Base/Utility/_store_cache
blob: 2fe7dfcb6aa55a1178d032d2b6342ece963b8063 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#autoload
#
# Storage component of completions caching layer

local _cache_ident
_cache_ident="$1"

if zstyle -t ":completion:${curcontext}:" use-cache; then
  # Decide which directory to cache to, and ensure it exists
  zstyle -s ":completion:${curcontext}:" cache-path _cache_dir
  : ${_cache_dir:=${ZDOTDIR:-$HOME}/.zcompcache}
  if [[ ! -d "$_cache_dir" ]]; then
    if [[ -e "$_cache_dir" ]]; then
      _message "cache-dir style points to a non-directory\!"
    else
      mkdir -p "$_cache_dir"
      if [[ ! -d "$_cache_dir" ]]; then
        _message "Couldn't create cache-dir $_cache_dir"
        return 1
      fi
    fi
  fi

  shift
  for var; do
    case ${(Pt)var} in
    (*readonly*) ;;
    (*(association|array)*) print -r "$var=( ${(kv@Pqq)^^var} )";;
    (*)                     print -r "$var=${(Pqq)^^var}";;
    esac
  done >! "$_cache_dir/$_cache_ident"
else
  return 1
fi

return 0