1

I'm trying to change the default location of the zsh completion cache files in macOS. I have read the zsh documentation on completion which say's "alternatively, an explicit file name can be given by ‘compinit -d dumpfile’" I set the ZCOMPCACHE variable and proceeded with the following code:

  ZCOMPCACHE="$HOME/.cache/zsh/zcompcache"

# Create the parent directory if it doesn't exist
[[ -d $ZCOMPCACHE ]] || mkdir -p $ZCOMPCACHE

# Set the custom location for zcompdump files
_comp_files=($HOME/.cache/zsh/zcompcache(Nm-20))
if (( $#_comp_files )); then
    compinit -i -C -d "$HOME/.cache/zsh/zcompcache/.zcompdump-${ZSH_VERSION}"
else
    compinit -i -d "$HOME/.cache/zsh/zcompcache/.zcompdump-${ZSH_VERSION}"
fi

# `unset` the temporary variable
unset _comp_files

The code works and creates the zcompcache directory under .cache/zsh and dumps the cache file to that location.

As shown here: Location of cache file

However, I'm still getting a .zcompdump file dumped in my $HOME directory even though I've set a specific location.

As shown here:
.zcompdump in home directory

I used to use oh-my-zsh but I found it too bloated for my requirements, could there be any residual settings left over from the previous oh-my-zsh configuration that may be causing the additional .zcompdump in my $HOME directory?

0

2 Answers 2

1

Update and fix.

I've updated my code to the following to fix the issue of two dump files being created.

ZSH_COMPDUMP="$HOME/.cache/zsh/zcompcache"

# Create the parent directory if it doesn't exist
[[ -d $ZSH_COMPDUMP ]] || mkdir -p $ZSH_COMPDUMP

_comp_files=($ZSH_COMPDUMP/zcompdump(Nm-20))
if (( $#_comp_files )); then
    autoload -Uz compinit -C -d "$ZSH_COMPDUMP/.zcompdump-${ZSH_VERSION}"
else
    autoload -Uz compinit -d "$ZSH_COMPDUMP/.zcompdump-${ZSH_VERSION}"
fi

The previous implementation had an issue where two dump files were being created because the compinit command was being called from outside the function. This resulted in a dump file being created in the $HOME directory and the one created by the code.

The code has been modified to call compinit inside the function to address this. This ensures that compinit is invoked only once while performing the necessary checks and applying the appropriate settings. By doing so, we resolve the duplication of dump files and ensure the correct behaviour of the code.

If anyone has any further insights or alternative suggestions, please drop me an answer.

Thanks

0

It looks like the .zcompdump file is created by /etc/zsh/zshrc. When you open the file there is a comment.

# If you don't want compinit called here, place the line
# skip_global_compinit=1
# in your $ZDOTDIR/.zshenv
if (( ${${(@f)"$(</etc/os-release)"}[(I)ID*=*ubuntu]} )) &&
   [[ -z "$skip_global_compinit" ]]; then
  autoload -U compinit
  compinit
fi

I had to create the .zshenv file and put skip_global_compinit=1 there, since then it does not create the .zcompdump file anymore.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .