2001-04-02 13:11:36 +02:00
|
|
|
#autoload
|
|
|
|
#
|
|
|
|
# Storage component of completions caching layer
|
|
|
|
|
2002-10-09 22:38:24 +02:00
|
|
|
local _cache_ident _cache_ident_dir
|
2001-04-02 13:11:36 +02:00
|
|
|
_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
|
2002-10-09 22:38:24 +02:00
|
|
|
(zmodload zsh/files 2>/dev/null; mkdir -p "$_cache_dir" )
|
2001-04-02 13:11:36 +02:00
|
|
|
if [[ ! -d "$_cache_dir" ]]; then
|
2002-04-16 09:48:43 +02:00
|
|
|
_message "couldn't create cache-dir $_cache_dir"
|
2001-04-02 13:11:36 +02:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
2002-10-09 22:38:24 +02:00
|
|
|
_cache_ident_dir="$_cache_dir/$_cache_ident"
|
|
|
|
_cache_ident_dir="$_cache_ident_dir:h"
|
|
|
|
|
|
|
|
if [[ ! -d "$_cache_ident_dir" ]]; then
|
|
|
|
if [[ -e "$_cache_ident_dir" ]]; then
|
|
|
|
_message "cache ident dir points to a non-directory:$_cache_ident_dir"
|
|
|
|
else
|
|
|
|
(zmodload zsh/files 2>/dev/null; mkdir -p "$_cache_ident_dir")
|
|
|
|
if [[ ! -d "$_cache_ident_dir" ]]; then
|
|
|
|
_message "couldn't create cache-ident_dir $_cache_ident_dir"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2001-04-02 13:11:36 +02:00
|
|
|
|
|
|
|
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
|