# If ZSH is not defined, use the current script's directory. [[ -n "$ZSH" ]] || export ZSH="${${(%):-%x}:a:h}" # Handle completions insecurities (i.e., completion-dependent directories with # insecure ownership or permissions) by: # # * Human-readably notifying the user of these insecurities. function handle_completion_insecurities() { # List of the absolute paths of all unique insecure directories, split on # newline from compaudit()'s output resembling: # # There are insecure directories: # /usr/share/zsh/site-functions # /usr/share/zsh/5.0.6/functions # /usr/share/zsh # /usr/share/zsh/5.0.6 # # Since the ignorable first line is printed to stderr and thus not captured, # stderr is squelched to prevent this output from leaking to the user. local -aU insecure_dirs insecure_dirs=( ${(f@):-"$(compaudit 2>/dev/null)"} ) # If no such directories exist, get us out of here. [[ -z "${insecure_dirs}" ]] && return # List ownership and permissions of all insecure directories. print "[oh-my-zsh] Insecure completion-dependent directories detected:" ls -ld "${(@)insecure_dirs}" cat </dev/null) || SHORT_HOST="${HOST/.*/}" else SHORT_HOST="${HOST/.*/}" fi # Save the location of the current completion dump file. if [[ -z "$ZSH_COMPDUMP" ]]; then ZSH_COMPDUMP="$HOME/.cache/shell/zcompdump-${SHORT_HOST}-${ZSH_VERSION}" fi # Construct zcompdump OMZ metadata zcompdump_revision="#omz revision: $(builtin cd -q "$ZSH"; git rev-parse HEAD 2>/dev/null)" zcompdump_fpath="#omz fpath: $fpath" # Delete the zcompdump file if OMZ zcompdump metadata changed if ! command grep -q -Fx "$zcompdump_revision" "$ZSH_COMPDUMP" 2>/dev/null \ || ! command grep -q -Fx "$zcompdump_fpath" "$ZSH_COMPDUMP" 2>/dev/null; then command rm -f "$ZSH_COMPDUMP" zcompdump_refresh=1 fi if [[ "$ZSH_DISABLE_COMPFIX" != true ]]; then # source "$ZSH/lib/compfix.zsh" # Load only from secure directories compinit -i -d "$ZSH_COMPDUMP" # If completion insecurities exist, warn the user handle_completion_insecurities &| else # If the user wants it, load from all found directories compinit -u -d "$ZSH_COMPDUMP" fi # Append zcompdump metadata if missing if (( $zcompdump_refresh )) \ || ! command grep -q -Fx "$zcompdump_revision" "$ZSH_COMPDUMP" 2>/dev/null; then # Use `tee` in case the $ZSH_COMPDUMP filename is invalid, to silence the error # See https://github.com/ohmyzsh/ohmyzsh/commit/dd1a7269#commitcomment-39003489 tee -a "$ZSH_COMPDUMP" &>/dev/null </dev/null; then zrecompile -q -p "$ZSH_COMPDUMP" command rm -rf "$ZSH_COMPDUMP.zwc.old" "${ZSH_COMPDUMP}.lock" fi