perf(cli): doomscript: reduce init time

In 4989661, I reduced the init time for bin/doom by eliminating the
extra `emacs` call in its shebang. This does the same for
bin/doomscript.

Ref: 498966179f
This commit is contained in:
Henrik Lissner 2024-09-11 17:55:33 -04:00
parent f27a85ed35
commit 5880348a6c
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -22,7 +22,16 @@ fi
case "$EMACS" in case "$EMACS" in
*term*) EMACS=emacs ;; # in {ansi-,v}term *term*) EMACS=emacs ;; # in {ansi-,v}term
*) EMACS="${EMACS:-emacs}" ;; *\ *) ;;
*) EMACS="${EMACS:-emacs}"
# Only sanity-check $EMACS if it's a path or executable
if ! type "$EMACS" >/dev/null 2>&1; then
echo "Error: failed to run Emacs with command '$EMACS'"
echo
echo "Are you sure Emacs is installed and in your \$PATH?"
exit 1
fi >&2
;;
esac esac
# Careful not to use -Q! It implies --no-site-lisp, which omits the site-lisp # Careful not to use -Q! It implies --no-site-lisp, which omits the site-lisp
@ -31,17 +40,6 @@ esac
# (like Snap or NixOS). # (like Snap or NixOS).
emacs="$EMACS -q --no-site-file --batch" emacs="$EMACS -q --no-site-file --batch"
# $TMPDIR (or $TEMP and $TMP on Windows) aren't guaranteed to have values, and
# mktemp isn't available on all systems, but you know what is? Emacs! So I rely
# on it to provide TMPDIR. And can second as a quick existence check for Emacs.
TMPDIR="${TMPDIR:-$($emacs --eval '(princ (temporary-file-directory))' 2>/dev/null)}"
if [ -z "$TMPDIR" ]; then
echo "Error: failed to run Emacs with command '$EMACS'"
echo
echo "Are you sure Emacs is installed and in your \$PATH?"
exit 1
fi >&2
# Doom respects $EMACSDIR to tell it where Doom lives. If it fails, then this is # Doom respects $EMACSDIR to tell it where Doom lives. If it fails, then this is
# either isn't bash, or it's a posix shell being directly sourced with sh, which # either isn't bash, or it's a posix shell being directly sourced with sh, which
# is unsupported. # is unsupported.
@ -79,6 +77,11 @@ exit=$?
# To simulate execve syscalls (which replaces the running process), Doom # To simulate execve syscalls (which replaces the running process), Doom
# generates a temporary exit-script if a Doomscript returns a 254 exit code. # generates a temporary exit-script if a Doomscript returns a 254 exit code.
if [ "${exit:-0}" -eq 254 ]; then if [ "${exit:-0}" -eq 254 ]; then
# $TMPDIR (or $TEMP and $TMP on Windows) aren't guaranteed to have values,
# and mktemp isn't available on all systems, but you know what is? Emacs! So
# I rely on it to provide TMPDIR.
export TMPDIR="${TMPDIR:-${TMP:-${TEMP:-$($emacs -Q --eval '(princ (temporary-file-directory))' 2>/dev/null)}}}"
# The user may have a noexec flag set on /tmp, so the exit-script should be # The user may have a noexec flag set on /tmp, so the exit-script should be
# passed to /bin/sh rather than executed directly. # passed to /bin/sh rather than executed directly.
sh "${TMPDIR}/doom.${__DOOMPID}.${__DOOMSTEP}.sh" "$0" "$@" sh "${TMPDIR}/doom.${__DOOMPID}.${__DOOMSTEP}.sh" "$0" "$@"