2014-02-24 16:09:08 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
2014-11-12 16:15:39 +01:00
|
|
|
_usage () {
|
|
|
|
cat<<EOF
|
2014-09-13 14:53:42 +02:00
|
|
|
Usage: ${1##*/} [OPTIONS] SCRIPT [ARGS...]
|
2014-02-24 16:09:08 +01:00
|
|
|
|
|
|
|
Run Emacs Lisp SCRIPT.
|
|
|
|
|
|
|
|
Options:
|
|
|
|
|
|
|
|
-b: Byte-compile before running.
|
|
|
|
-c: Remove byte code once finished.
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
OPT_BYTE=false
|
|
|
|
OPT_CLEAN=false
|
|
|
|
while getopts :bc OPT; do
|
2014-11-12 16:15:39 +01:00
|
|
|
case $OPT in
|
|
|
|
b)
|
|
|
|
OPT_BYTE=true ;;
|
|
|
|
c)
|
|
|
|
OPT_CLEAN=true ;;
|
|
|
|
\?)
|
|
|
|
_usage "$0"
|
|
|
|
exit 1 ;;
|
|
|
|
esac
|
2014-02-24 16:09:08 +01:00
|
|
|
done
|
|
|
|
|
2016-06-23 23:18:36 +02:00
|
|
|
shift $((OPTIND - 1))
|
2014-02-24 16:09:08 +01:00
|
|
|
if [ $# -eq 0 ]; then
|
2014-11-12 16:15:39 +01:00
|
|
|
_usage "$0"
|
|
|
|
exit 1
|
2014-02-24 16:09:08 +01:00
|
|
|
fi
|
|
|
|
|
2014-09-13 14:53:42 +02:00
|
|
|
if ! command -v emacs >/dev/null 2>&1; then
|
2014-11-12 16:15:39 +01:00
|
|
|
echo 'emacs not found in PATH. Exiting.' >&2
|
|
|
|
exit 1
|
2014-09-13 14:53:42 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
script="$1"
|
2014-02-24 16:09:08 +01:00
|
|
|
if $OPT_BYTE && [ "${1##*.}" = "el" ]; then
|
2014-11-12 16:15:39 +01:00
|
|
|
script="${1%.*}.elc"
|
|
|
|
emacs -Q --batch -f batch-byte-compile "$1" 2>/dev/null
|
2014-02-24 16:09:08 +01:00
|
|
|
fi
|
2014-09-13 14:53:42 +02:00
|
|
|
shift
|
2014-02-24 16:09:08 +01:00
|
|
|
|
2014-09-14 22:15:09 +02:00
|
|
|
emacs -Q --script "$script" "$@" 2>&1
|
2014-02-24 16:09:08 +01:00
|
|
|
$OPT_CLEAN && rm "$script"
|
2014-09-14 00:29:34 +02:00
|
|
|
|
|
|
|
## WARNING: never leave a script on a condition, return code be unexpectedly != 0.
|
|
|
|
exit 0
|