spack setup-env.sh: make zsh loading async compatible, and ~10x faster (in some cases) (#26120)

Currently spack is a bit of a bad actor as a zsh plugin, and it was my
fault.  The autoload and compinit should really be handled by the user,
as was made abundantly clear when I found spack was doing completion
initialization for *all* of my plugins due to a deferred setup that was
getting messed up by it.

Making this conditional took spack load time from 1.5 seconds (with
module loading disabled) to 0.029 seconds. I can actually afford to load
spack by default with this change in.

Hopefully someday we'll do proper zsh completion support, but for now
this helps a lot.

* use zsh hist expansion in place of dirname
* only run (bash)compinit if compdef/complete missing
* add zsh compiled files to .gitignore
* move changes to .in file, because spack
This commit is contained in:
Tom Scogland 2021-10-28 11:32:59 -07:00 committed by GitHub
parent 5faa457a35
commit 87e456d59c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 10 deletions

3
.gitignore vendored
View file

@ -210,6 +210,9 @@ tramp
/eshell/history
/eshell/lastdir
# zsh byte-compiled files
*.zwc
# elpa packages
/elpa/

View file

@ -39,10 +39,14 @@
if test -n "${ZSH_VERSION:-}" ; then
if [[ "$(emulate)" = zsh ]] ; then
# ensure base completion support is enabled, ignore insecure directories
autoload -U +X compinit && compinit -i
# ensure bash compatible completion support is enabled
autoload -U +X bashcompinit && bashcompinit
if ! typeset -f compdef >& /dev/null ; then
# ensure base completion support is enabled, ignore insecure directories
autoload -U +X compinit && compinit -i
fi
if ! typeset -f complete >& /dev/null ; then
# ensure bash compatible completion support is enabled
autoload -U +X bashcompinit && bashcompinit
fi
emulate sh -c "source '$0:A'"
return # stop interpreting file
fi

View file

@ -276,8 +276,13 @@ fi
#
# We send cd output to /dev/null to avoid because a lot of users set up
# their shell so that cd prints things out to the tty.
_sp_share_dir="$(cd "$(dirname $_sp_source_file)" > /dev/null && pwd)"
_sp_prefix="$(cd "$(dirname $(dirname $_sp_share_dir))" > /dev/null && pwd)"
if [ "$_sp_shell" = zsh ]; then
_sp_share_dir="${_sp_source_file:A:h}"
_sp_prefix="${_sp_share_dir:h:h}"
else
_sp_share_dir="$(cd "$(dirname $_sp_source_file)" > /dev/null && pwd)"
_sp_prefix="$(cd "$(dirname $(dirname $_sp_share_dir))" > /dev/null && pwd)"
fi
if [ -x "$_sp_prefix/bin/spack" ]; then
export SPACK_ROOT="${_sp_prefix}"
else

View file

@ -39,10 +39,14 @@
if test -n "${ZSH_VERSION:-}" ; then
if [[ "$(emulate)" = zsh ]] ; then
# ensure base completion support is enabled, ignore insecure directories
autoload -U +X compinit && compinit -i
# ensure bash compatible completion support is enabled
autoload -U +X bashcompinit && bashcompinit
if ! typeset -f compdef >& /dev/null ; then
# ensure base completion support is enabled, ignore insecure directories
autoload -U +X compinit && compinit -i
fi
if ! typeset -f complete >& /dev/null ; then
# ensure bash compatible completion support is enabled
autoload -U +X bashcompinit && bashcompinit
fi
emulate sh -c "source '$0:A'"
return # stop interpreting file
fi