Skip to content

Commit

Permalink
Make .zcomp* location configurable (sorin-ionescu#1842)
Browse files Browse the repository at this point in the history
  • Loading branch information
texastoland authored and Maciej Kucharek committed Feb 8, 2021
1 parent aac78d9 commit dec120f
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 17 deletions.
3 changes: 2 additions & 1 deletion modules/command-not-found/init.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ elif (( $+commands[brew] )); then
"$(brew --repository 2> /dev/null)"/Library/Taps/*/*/cmd/brew-command-not-found-init(|.rb)(.N)
)
if (( $#cnf_command )); then
cache_file="${TMPDIR:-/tmp}/prezto-brew-command-not-found-cache.$UID.zsh"
cache_file="${XDG_CACHE_HOME:-$HOME/.cache}/prezto/brew-command-not-found-cache.zsh"

if [[ "${${(@o)cnf_command}[1]}" -nt "$cache_file" \
|| "${ZDOTDIR:-$HOME}/.zpreztorc" -nt "$cache_file" \
|| ! -s "$cache_file" ]]; then
mkdir -p "$cache_file:h"
# brew command-not-found-init is slow; cache its output.
brew command-not-found-init >! "$cache_file" 2> /dev/null
fi
Expand Down
15 changes: 9 additions & 6 deletions modules/completion/init.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,24 @@ unsetopt FLOW_CONTROL # Disable start/stop characters in shell editor.
# cache time of 20 hours, so it should almost always regenerate the first time a
# shell is opened each day.
autoload -Uz compinit
_comp_files=(${ZDOTDIR:-$HOME}/.zcompdump(Nm-20))
if (( $#_comp_files )); then
compinit -i -C
_comp_path="${XDG_CACHE_HOME:-$HOME/.cache}/prezto/zcompdump"
# #q expands globs in conditional expressions
if [[ $_comp_path(#qNmh-20) ]]; then
# -C (skip function check) implies -i (skip security check).
compinit -C -d "$_comp_path"
else
compinit -i
mkdir -p "$_comp_path:h"
compinit -i -d "$_comp_path"
fi
unset _comp_files
unset _comp_path

#
# Styles
#

# Use caching to make completion for commands such as dpkg and apt usable.
zstyle ':completion::complete:*' use-cache on
zstyle ':completion::complete:*' cache-path "${ZDOTDIR:-$HOME}/.zcompcache"
zstyle ':completion::complete:*' cache-path "${XDG_CACHE_HOME:-$HOME/.cache}/prezto/zcompcache"

# Case-insensitive (all), partial-word, and then substring completion.
if zstyle -t ':prezto:module:completion:*' case-sensitive; then
Expand Down
3 changes: 2 additions & 1 deletion modules/fasd/init.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fi
# Initialization
#

cache_file="${TMPDIR:-/tmp}/prezto-fasd-cache.$UID.zsh"
cache_file="${XDG_CACHE_HOME:-$HOME/.cache}/prezto/fasd-cache.zsh"
if [[ "${commands[fasd]}" -nt "$cache_file" \
|| "${ZDOTDIR:-$HOME}/.zpreztorc" -nt "$cache_file" \
|| ! -s "$cache_file" ]]; then
Expand All @@ -31,6 +31,7 @@ if [[ "${commands[fasd]}" -nt "$cache_file" \
init_args+=(zsh-ccomp zsh-ccomp-install zsh-wcomp zsh-wcomp-install)
fi

mkdir -p "$cache_file:h"
# Cache init code.
fasd --init "$init_args[@]" >! "$cache_file" 2> /dev/null
fi
Expand Down
3 changes: 2 additions & 1 deletion modules/gpg/init.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fi

# Set the default paths to gpg-agent files.
_gpg_agent_conf="${GNUPGHOME:-$HOME/.gnupg}/gpg-agent.conf"
_gpg_agent_env="${TMPDIR:-/tmp}/gpg-agent.env.$UID"
_gpg_agent_env="${XDG_CACHE_HOME:-$HOME/.cache}/prezto/gpg-agent.env"

# Load environment variables from previous run
source "$_gpg_agent_env" 2> /dev/null
Expand All @@ -21,6 +21,7 @@ source "$_gpg_agent_env" 2> /dev/null
if [[ -z "$GPG_AGENT_INFO" && ! -S "${GNUPGHOME:-$HOME/.gnupg}/S.gpg-agent" ]]; then
# Start gpg-agent if not started.
if ! ps -U "$LOGNAME" -o pid,ucomm | grep -q -- "${${${(s.:.)GPG_AGENT_INFO}[2]}:--1} gpg-agent"; then
mkdir -p "$_gpg_agent_env:h"
eval "$(gpg-agent --daemon | tee "$_gpg_agent_env")"
fi
fi
Expand Down
3 changes: 2 additions & 1 deletion modules/node/init.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ typeset -A compl_commands=(

for compl_command in "${(k)compl_commands[@]}"; do
if (( $+commands[$compl_command] )); then
cache_file="${TMPDIR:-/tmp}/prezto-$compl_command-cache.$UID.zsh"
cache_file="${XDG_CACHE_HOME:-$HOME/.cache}/prezto/$compl_command-cache.zsh"

# Completion commands are slow; cache their output if old or missing.
if [[ "$commands[$compl_command]" -nt "$cache_file" \
|| "${ZDOTDIR:-$HOME}/.zpreztorc" -nt "$cache_file" \
|| ! -s "$cache_file" ]]; then
mkdir -p "$cache_file:h"
command ${=compl_commands[$compl_command]} >! "$cache_file" 2> /dev/null
fi

Expand Down
4 changes: 2 additions & 2 deletions modules/pacman/functions/pacman-list-disowned
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

# function pacman-list-disowned {

local tmp="${TMPDIR:-/tmp}/pacman-disowned-$UID-$$"
local tmp="${XDG_CACHE_HOME:-$HOME/.cache}/prezto/pacman-disowned-$$"
local db="$tmp/db"
local fs="$tmp/fs"

mkdir "$tmp"
mkdir -p "$tmp"
trap 'rm -rf "$tmp"' EXIT

pacman --quiet --query --list | sort --unique > "$db"
Expand Down
3 changes: 2 additions & 1 deletion modules/perl/init.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ fi

if is-darwin; then
# Perl is slow; cache its output.
cache_file="${TMPDIR:-/tmp}/prezto-perl-cache.$UID.zsh"
cache_file="${XDG_CACHE_HOME:-$HOME/.cache}/prezto/perl-cache.zsh"
perl_path="$HOME/Library/Perl/5.12"

if [[ -f "$perl_path/lib/perl5/local/lib.pm" ]]; then
if [[ "${ZDOTDIR:-$HOME}/.zpreztorc" -nt "$cache_file" || ! -s "$cache_file" ]]; then
mkdir -p "$cache_file:h"
perl -I$perl_path/lib/perl5 -Mlocal::lib=$perl_path >! "$cache_file"
fi

Expand Down
3 changes: 2 additions & 1 deletion modules/python/init.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,15 @@ fi

# Load PIP completion.
if (( $#commands[(i)pip(|[23])] )); then
cache_file="${TMPDIR:-/tmp}/prezto-pip-cache.$UID.zsh"
cache_file="${XDG_CACHE_HOME:-$HOME/.cache}/prezto/pip-cache.zsh"

# Detect and use one available from among 'pip', 'pip2', 'pip3' variants
pip_command="$commands[(i)pip(|[23])]"

if [[ "$pip_command" -nt "$cache_file" \
|| "${ZDOTDIR:-$HOME}/.zpreztorc" -nt "$cache_file" \
|| ! -s "$cache_file" ]]; then
mkdir -p "$cache_file:h"
# pip is slow; cache its output. And also support 'pip2', 'pip3' variants
$pip_command completion --zsh \
| sed -e "s/\(compctl -K [-_[:alnum:]]* pip\).*/\1{,2,3}{,.{0..9}}/" \
Expand Down
6 changes: 4 additions & 2 deletions modules/ssh/init.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ fi
_ssh_dir="$HOME/.ssh"

# Set the path to the environment file if not set by another module.
_ssh_agent_env="${_ssh_agent_env:-${TMPDIR:-/tmp}/ssh-agent.env.$UID}"
_ssh_agent_env="${_ssh_agent_env:-${XDG_CACHE_HOME:-$HOME/.cache}/prezto/ssh-agent.env}"

# Set the path to the persistent authentication socket.
_ssh_agent_sock="${TMPDIR:-/tmp}/ssh-agent.sock.$UID"
_ssh_agent_sock="${XDG_CACHE_HOME:-$HOME/.cache}/prezto/ssh-agent.sock"

# Start ssh-agent if not started.
if [[ ! -S "$SSH_AUTH_SOCK" ]]; then
Expand All @@ -26,12 +26,14 @@ if [[ ! -S "$SSH_AUTH_SOCK" ]]; then

# Start ssh-agent if not started.
if ! ps -U "$LOGNAME" -o pid,ucomm | grep -q -- "${SSH_AGENT_PID:--1} ssh-agent"; then
mkdir -p "$_ssh_agent_env:h"
eval "$(ssh-agent | sed '/^echo /d' | tee "$_ssh_agent_env")"
fi
fi

# Create a persistent SSH authentication socket.
if [[ -S "$SSH_AUTH_SOCK" && "$SSH_AUTH_SOCK" != "$_ssh_agent_sock" ]]; then
mkdir -p "$_ssh_agent_sock:h"
ln -sf "$SSH_AUTH_SOCK" "$_ssh_agent_sock"
export SSH_AUTH_SOCK="$_ssh_agent_sock"
fi
Expand Down
2 changes: 1 addition & 1 deletion runcoms/zlogin
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Execute code that does not affect the current session in the background.
{
# Compile the completion dump to increase startup speed.
zcompdump="${ZDOTDIR:-$HOME}/.zcompdump"
zcompdump="${XDG_CACHE_HOME:-$HOME/.cache}/prezto/zcompdump"
if [[ -s "$zcompdump" && (! -s "${zcompdump}.zwc" || "$zcompdump" -nt "${zcompdump}.zwc") ]]; then
zcompile "$zcompdump"
fi
Expand Down

0 comments on commit dec120f

Please sign in to comment.