From fd3a55f78b1e316727760a92dcd3f0759013549c Mon Sep 17 00:00:00 2001 From: Frank Terbeck Date: Fri, 9 Oct 2015 16:16:16 +0200 Subject: [PATCH] zshrc: Add more robustness to completion caching setup [Closes: issue1933] This is based on a suggestion by Thilo Six . The setup now uses $GRML_COMP_CACHING to decide on whether to configure caching at all and $GRML_COMP_CACHE_DIR to tell where to put the caching data. It also makes sure the caching directory actually exists before using it. See the included documentation for details. Signed-off-by: Frank Terbeck --- doc/grmlzshrc.t2t | 9 +++++++++ etc/zsh/zshrc | 13 ++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/doc/grmlzshrc.t2t b/doc/grmlzshrc.t2t index ead2182..8accb74 100644 --- a/doc/grmlzshrc.t2t +++ b/doc/grmlzshrc.t2t @@ -55,6 +55,15 @@ Deprecated. Use **GRML_DISPLAY_BATTERY** instead. A non zero value activates a handler, which is called when a command can not be found. The handler is defined by GRML_ZSH_CNF_HANDLER (see below). +: **GRML_COMP_CACHING** +If set to //yes// (the default), the setup will enable zsh's completion caching +mechanism, with the caching data being placed into //$GRML_COMP_CACHE_DIR//. + +: **GRML_COMP_CACHE_DIR** +This defines where zsh's completion caching data will be placed, if +//$GRML_COMP_CACHING// is active. The default is //${ZDOTDIR:-$HOME}/.cache//. +The setup will ensure the directory exists before attempting to use it. + : **GRML_DISPLAY_BATTERY** If set to a value greater than zero, //grmlzshrc// will put the battery status into the right hand side interactive prompt. Supported OSes are //GNU/Linux//, diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index a6f9670..80828e0 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -805,9 +805,16 @@ grmlcomp() { # command for process lists, the local web server details and host completion zstyle ':completion:*:urls' local 'www' '/var/www/' 'public_html' - # caching - [[ -d $ZSHDIR/cache ]] && zstyle ':completion:*' use-cache yes && \ - zstyle ':completion::complete:*' cache-path $ZSHDIR/cache/ + # Some functions, like _apt and _dpkg, are very slow. We can use a cache in + # order to speed things up + if [[ ${GRML_COMP_CACHING:-yes} == yes ]]; then + GRML_COMP_CACHE_DIR=${GRML_COMP_CACHE_DIR:-${ZDOTDIR:-$HOME}/.cache} + if [[ ! -d ${GRML_COMP_CACHE_DIR} ]]; then + command mkdir -p "${GRML_COMP_CACHE_DIR}" + fi + zstyle ':completion:*' use-cache yes + zstyle ':completion:*:complete:*' cache-path "${GRML_COMP_CACHE_DIR}" + fi # host completion if is42 ; then -- 2.1.4