feat(cli): resolve EMACSDIR to doomscript's parent directory

If no EMACSDIR is given, assume ../ is the Emacs config we want to
operate out of, taking after bin/doom.

And use bash. This script was designed for the convenience of other
scripters on unix systems, so it can afford a small hit to portability.
This commit is contained in:
Henrik Lissner 2022-06-19 01:59:56 +02:00
parent 74f3c1d11c
commit 09ddac1d7a
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -1,4 +1,4 @@
#!/usr/bin/env sh
#!/usr/bin/env bash
# This is a shebang interpreter for launching emacs lisp scripts with Doom's CLI
# framework preloaded and all the metadata it needs initialized. Use it like so:
#
@ -22,7 +22,7 @@ case "$EMACS" in
*) EMACS="${EMACS:-emacs}" ;;
esac
TMPDIR=${TMPDIR:-`$EMACS -Q --batch --eval '(princ (temporary-file-directory))' 2>/dev/null`}
TMPDIR="${TMPDIR:-$($EMACS -Q --batch --eval '(princ (temporary-file-directory))' 2>/dev/null)}"
if [ -z "$TMPDIR" ]; then
>&2 echo "Error: failed to run Emacs with command '$EMACS'"
>&2 echo
@ -30,15 +30,7 @@ if [ -z "$TMPDIR" ]; then
exit 1
fi
if [ -z "$EMACSDIR" ]; then
EMACSDIR="${XDG_CONFIG_HOME:-$HOME/.config}/emacs"
[ -d "$EMACSDIR" ] || EMACSDIR="$HOME/.emacs.d"
if [ ! -d "$EMACSDIR" ]; then
>&2 echo "Failed to find \$EMACSDIR in ~/.config/emacs or ~/.emacs.d"
exit 1
fi
fi
export EMACSDIR="${EMACSDIR:-$(cd $(dirname "$BASH_SOURCE")/.. && pwd)}"
export __DOOMPID="${__DOOMPID:-$$}"
export __DOOMSTEP="$((__DOOMSTEP+1))"
export __DOOMGEOM="${__DOOMGEOM:-`tput cols lines 2>/dev/null`}"