1
0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2026-02-11 05:39:45 +08:00
ohmyzsh-mirror/hooks/zshenv
2026-02-03 20:17:48 +01:00

59 lines
1.6 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

omzp:start() {
setopt localoptions localtraps
# initialization
zmodload zsh/datetime
typeset -Ag __OMZP
__OMZP=(
PS4 "$PS4"
start "$EPOCHREALTIME"
outfile "${1:-$HOME}/${${SHELL:t}#-}.$EPOCHSECONDS.$$.zsh-trace.log"
)
typeset -g PS4="+Z|%e|%D{%s.%9.}|%N|%x|%I> "
# unload profiler on startup end
autoload -Uz add-zsh-hook
add-zsh-hook precmd omzp:stop
# redirect debug output to profiler log file
exec 3>&2 2>${__OMZP[outfile]}
# enable zsh debug mode
trap 'setopt xtrace noevallineno' EXIT
}
# Force this function to be executed in noxtrace mode
emulate zsh +x -c '
omzp:stop() {
setopt localoptions localtraps
trap "{ setopt noxtrace evallineno } 2>/dev/null; exec 2>&3 3>&-" EXIT
# restore PS4
typeset -g PS4="$__OMZP[PS4]"
unset "__OMZP[PS4]"
# remove precmd function
add-zsh-hook -d precmd omzp:stop
unfunction omzp:stop
local startup=$(( (${(%):-"%D{%s.%9.}"} - __OMZP[start]) * 1e3 ))
printf "%.3f ms %s \n" "$startup" "${__OMZP[outfile]:t}"
}'
# TODO: this is duplicated from init script, fix later
# Init $ZSH path
[[ -n "$ZSH" ]] || export ZSH="${${(%):-%x}:a:h:h}"
# Set ZSH_CACHE_DIR to the path where cache files should be created
# or else we will use the default cache/
[[ -n "$ZSH_CACHE_DIR" ]] || ZSH_CACHE_DIR="$ZSH/cache"
# Make sure $ZSH_CACHE_DIR is writable, otherwise use a directory in $HOME
if [[ ! -w "$ZSH_CACHE_DIR" ]]; then
ZSH_CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/oh-my-zsh"
fi
# Set OMZ_TRACES directory
OMZ_TRACES="${OMZ_TRACES:-"$ZSH_CACHE_DIR/.traces"}"
! 'builtin' 'test' -f "${OMZ_TRACES}/.enabled" || omzp:start "$OMZ_TRACES"