2022-06-19 01:59:56 +02:00
|
|
|
#!/usr/bin/env bash
|
2022-06-22 19:37:27 +02:00
|
|
|
# This is a shebang interpreter for launching Emacs Lisp scripts with Doom's CLI
|
|
|
|
# framework preloaded, plus any environment variables it needs. Use it like so:
|
2022-06-18 23:13:44 +02:00
|
|
|
#
|
|
|
|
# #!/usr/bin/env doomscript
|
|
|
|
# (print! "Hello world!")
|
|
|
|
#
|
2022-06-22 19:37:27 +02:00
|
|
|
# For this to work (and to avoid absolute paths in your shebang line), I
|
|
|
|
# recommend having this file in your $PATH:
|
2022-06-18 23:13:44 +02:00
|
|
|
#
|
|
|
|
# export PATH="$HOME/.emacs.d/bin:$PATH"
|
|
|
|
#
|
2022-06-22 19:37:27 +02:00
|
|
|
# This isn't used for bin/doom because of the $PATH/absolute path requirement
|
|
|
|
# (and using $BASH_SOURCE to locate it would reduce its POSIX compliance), but
|
|
|
|
# this shouldn't be an issue for folks writing their own CLIs.
|
2022-06-18 23:13:44 +02:00
|
|
|
|
|
|
|
case "$EMACS" in
|
|
|
|
*term*) EMACS=emacs ;;
|
|
|
|
*) EMACS="${EMACS:-emacs}" ;;
|
|
|
|
esac
|
|
|
|
|
2022-06-21 22:38:06 +02:00
|
|
|
emacs="$EMACS -q --no-site-file --no-x-resources --no-splash --batch"
|
|
|
|
|
|
|
|
TMPDIR="${TMPDIR:-$($emacs --eval '(princ (temporary-file-directory))' 2>/dev/null)}"
|
2022-06-18 23:13:44 +02:00
|
|
|
if [ -z "$TMPDIR" ]; then
|
|
|
|
>&2 echo "Error: failed to run Emacs with command '$EMACS'"
|
|
|
|
>&2 echo
|
|
|
|
>&2 echo "Are you sure Emacs is installed and in your \$PATH?"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-06-19 01:59:56 +02:00
|
|
|
export EMACSDIR="${EMACSDIR:-$(cd $(dirname "$BASH_SOURCE")/.. && pwd)}"
|
2022-06-18 23:13:44 +02:00
|
|
|
export __DOOMPID="${__DOOMPID:-$$}"
|
|
|
|
export __DOOMSTEP="$((__DOOMSTEP+1))"
|
|
|
|
export __DOOMGEOM="${__DOOMGEOM:-`tput cols lines 2>/dev/null`}"
|
|
|
|
export __DOOMGPIPE=${__DOOMGPIPE:-$__DOOMPIPE}
|
|
|
|
export __DOOMPIPE=; [ -t 0 ] || __DOOMPIPE+=0; [ -t 1 ] || __DOOMPIPE+=1
|
|
|
|
|
|
|
|
tmpfile="$TMPDIR/doomscript.${__DOOMPID}"
|
|
|
|
|
|
|
|
target="$1"
|
|
|
|
shift
|
2022-07-30 21:49:00 +02:00
|
|
|
$emacs --load "$EMACSDIR/lisp/doom-cli" \
|
2022-06-21 22:38:06 +02:00
|
|
|
--load "$target" \
|
|
|
|
-- "$@" || exit=$?
|
2022-06-18 23:13:44 +02:00
|
|
|
# Execute exit-script, if requested (to simulate execve)
|
|
|
|
if [ "${exit:-0}" -eq 254 ]; then
|
|
|
|
sh "${tmpdir}/doom.${__DOOMPID}.${__DOOMSTEP}.sh" "$0" "$@" && true
|
|
|
|
exit="$?"
|
|
|
|
fi
|
|
|
|
exit $exit
|